-4

如何使用照片Framework (iOS 8.0)?我想得到一个可以在UICollectionView.

4

1 回答 1

0

如果你想要一个包含所有图像的 fetchResult,你可以这样解决它:

// Property in your UICollectionViewController.h file
@property (strong, nonatomic) PHFetchResult *allPhotosFetchResult;

// In your awakeFromNib or where you refresh your Data
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
self.allPhotosFetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];

在您的 collectionView:cellForItemAtIndexPath: 方法中,您可以使用

self.allPhotosFetchResult[indexPath.row];

要获取 collectionView:numberOfItemsInSection 中的行数:

self.allPhotosFetchResult.count
于 2015-03-24T09:59:34.793 回答