2014-02-22 146 views
0
ALAssetsLibraryGroupsEnumerationResultsBlock groupsEnumerationBlock = ^(ALAssetsGroup *group, BOOL *stop) { 
    if ([groupName compare:[group valueForProperty:ALAssetsGroupPropertyName]] == NSOrderedSame){ 
     self.assetsGroup = group; 
     NSLog(@"Has found the target group"); 
     return ; 
    } 
    ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 
     if (result) { 
      [self.assets addObject:result]; 
      NSLog(@"%@",self.assets); 
     } 
    }; 
    ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 
    [self.assetsGroup setAssetsFilter:onlyPhotosFilter]; 
    [self.assetsGroup enumerateAssetsUsingBlock:assetsEnumerationBlock]; 
}; 

ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) { 
    NSString *errorMessage = nil; 
    switch ([error code]) { 
     case ALAssetsLibraryAccessUserDeniedError: 
     case ALAssetsLibraryAccessGloballyDeniedError: 
      errorMessage = @"The user has declined access to it."; 
      break; 
     default: 
      errorMessage = @"Reason unknown."; 
      break; 
    } 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" 
                message:[NSString stringWithFormat:@"%@",errorMessage] 
                delegate:self 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil, nil]; 
    [alert show]; 
}; 

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces | ALAssetsGroupSavedPhotos; 
[self.library enumerateGroupsWithTypes:groupTypes 
          usingBlock:groupsEnumerationBlock failureBlock:failureBlock]; 

我想显示在collectinView.I在特殊的相册照片可以得到enumerationBlock里面的数据,但不能使用self.assets显示collection.I'm不是很熟悉块。我可以如何解决问题?显示照片与ALAsset

回答

0

要在UIImageView显示ALAssets

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
    ALAsset *asset = [self.assets objectAtIndex:indexPath.row]; 
    UIImage *image = [[asset defaultRepresentation] fullScreenImage]; 

    [cell.imageView setImage:image] 

    return cell; 
} 

如果您定位所需资产后打电话[self.collectionView reloadData],你要善于去。

+0

我应该在哪里调用[self.collectionView reloadData]?我把它叫做后[self.assetsGroup enumerateAssetsUsingBlock:assetsEnumerationBlock]。 在viewDidLoad中但都无法显示 – user3341264

+0

我位置的资产'''awakeFromNib:'''我重装后'''[self.assetsGroup enumerateAssetsUsingBlock:assetsEnumerationBlock]我收集的看法;'''。这很难说,为什么这个失败不看,当你加载你的资产,以及您UICollectionViewDatasource期待......如果能够将资产添加到self.assets,你应该能够重新加载您的收藏视图显示他们在你完成定位之后。 –

相关问题