-4

How to use photos Framework (iOS 8.0)? I wanna get one result that can show one by one image in the UICollectionView.

Michal
  • 15,429
  • 10
  • 73
  • 104
Alisa_stranger
  • 71
  • 1
  • 1
  • 7

1 Answers1

0

If you want a fetchResult with all images, you can solve it like this:

// 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];

In your collectionView:cellForItemAtIndexPath: method you can access the asset with

self.allPhotosFetchResult[indexPath.row];

To get the number of rows in collectionView:numberOfItemsInSection:

self.allPhotosFetchResult.count
Thyraz
  • 2,412
  • 2
  • 21
  • 23
  • thank you very much ! But How to display pictures one by one in the UICollectionView ?Not all the photos displayed at once – Alisa_stranger Mar 25 '15 at 02:02
  • What do you mean with "one by one"? Each cell displays one asset/image. Everything else is based on your cellSize and CollectionViewLayout. You should really clarify your question above. – Thyraz Mar 25 '15 at 08:19
  • I am so sorry about this.Thank you very much ,I have already solve this issue. Wish U have a great day~ – Alisa_stranger Mar 25 '15 at 10:08