2014-02-11 5 views
1

내 라이브러리의 모든 ALAssets을 포함하는 NSArray가 있습니다. 이 자산의 이름으로 필터링해야합니다. ALAssetRepresention을 통해 자산 이름 만 가진 두 번째 배열을 만들려고했습니다. 그렇다면 엄지 손톱을 보여줄 수없고 자산에 대한 링크를 저장할 수 없습니다. 그럼 어떻게 해결할 수 있습니까?ALAssets의 NSPredicate 및 NSArray

답변

1

모든 개체 (예 : 이름, 미리보기 이미지 및 URL)를 하나의 개체에 저장 한 다음 모든 개체를 하나의 배열에 저장해야합니다. 나는 이름이 "_ 제목"나는이 문제를 다음 방법으로 해결

+0

나는 당신의 생각을 이해하지 못했습니다. :(이 항목을 정렬 할 필요가 없습니다. 검색보기에 필터를 적용해야합니다. –

1

에있는 NSString를 포함하는 객체의 이름을 저장

NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"ItemTitle" 
                 ascending:YES 
                 selector:@selector(localizedStandardCompare:)]; 

[arrData sortUsingDescriptors:[NSArray arrayWithObject:sorter]]; 

: 그럼이 코드를 사용합니다. SearchItems 개체는 두 개의 값, 즉 NSString *nameALAsset *asset을 포함하고 있습니다. 내가 라이브러리에서 파일을 열거있을 때, 내가 설정 값 : [assetsItems addObject:newItem];

그리고 마침내 나는 name로 내 배열을 필터링하는 자 NSPredicate를 사용 :

ALAssetRepresentation *rep = [result defaultRepresentation]; 

SearchItem *newItem = [[SearchItem alloc] init]; 
[newItem setName:[rep filename]]; 
[newItem setAsset:result]; 

은 그 때 나는 내 NSMutableArray이 항목을 추가

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", searchText]; 
    _searchResults = [self.assetsItems filteredArrayUsingPredicate:resultPredicate]; 

이제 배열을 가져올 준비가되었습니다. 표보기의 예 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"SearchCell"; 

    SearchCell *cell = (SearchCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    // Configure the cell... 
    if (cell == nil) { 
     cell = [[SearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

    // Configure the cell... 
    SearchItem *searchItem = [_searchResults objectAtIndex:indexPath.row]; 
    ALAsset *currentAsset = searchItem.asset; 
    ALAssetRepresentation *rep = [currentAsset defaultRepresentation]; 

    [cell.nameLabel setText:[rep filename]]; 
    [cell.thumbnail setImage:[UIImage imageWithCGImage:[currentAsset thumbnail]]]; 

    return cell; 
} 

그게 전부입니다. 나는 그것이 미래에 누군가를 도울 것이라고 희망한다.