RITLPhotosBrowseDataSource.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // RITLPhotosBrowseDataSource.m
  3. // RITLPhotoDemo
  4. //
  5. // Created by YueWen on 2018/5/18.
  6. // Copyright © 2018年 YueWen. All rights reserved.
  7. //
  8. #import "RITLPhotosBrowseDataSource.h"
  9. #import "PHAsset+RITLPhotos.h"
  10. #import "UICollectionViewCell+RITLPhotosAsset.h"
  11. @interface RITLPhotosBrowseDataSource()
  12. ///进行资源化的Manager
  13. @property (nonatomic, strong, readwrite) PHCachingImageManager* imageManager;
  14. @end
  15. @implementation RITLPhotosBrowseDataSource
  16. - (instancetype)init
  17. {
  18. if (self = [super init]) {
  19. self.imageManager = PHCachingImageManager.new;
  20. }
  21. return self;
  22. }
  23. #pragma mark - <UICollectionViewDataSource>
  24. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  25. {
  26. return self.assets.count;
  27. }
  28. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  29. {
  30. //获得当前的对象
  31. PHAsset *asset = self.assets[indexPath.item];
  32. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:asset.ritl_type forIndexPath:indexPath];
  33. [cell updateAssets:asset atIndexPath:indexPath imageManager:self.imageManager];//即将显示,进行填充
  34. return cell;
  35. }
  36. #pragma mark - <RITLPhotosHorBrowseDataSource>
  37. - (PHAsset *)assetAtIndexPath:(NSIndexPath *)indexPath
  38. {
  39. return self.assets[indexPath.item];
  40. }
  41. - (NSIndexPath *)defaultItemIndexPath
  42. {
  43. return [NSIndexPath indexPathForItem:0 inSection:0];
  44. }
  45. - (void)dealloc
  46. {
  47. NSLog(@"[%@] is dealloc",NSStringFromClass(self.class));
  48. }
  49. @end