RAPhotoCell.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // RAPhotoCell.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/10/30.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAPhotoCell.h"
  9. #import "RAPhotoItemCell.h"
  10. #import "RAPhotoModel.h"
  11. #import "RAPhotoModelDelegate.h"
  12. #import "RAPhotoLayout.h"
  13. @interface RAPhotoCell ()<UICollectionViewDelegate,UICollectionViewDataSource,RAPhotoModelDelegate>
  14. @property (nonatomic,strong) IBOutlet UILabel *titleLabel;
  15. @property (nonatomic,strong) IBOutlet UILabel *requiredLabel;
  16. @property (nonatomic,strong) IBOutlet UICollectionView *photoCollectionView;
  17. @property (nonatomic,strong) RAPhotoLayout *photoLayout;
  18. @end
  19. @implementation RAPhotoCell
  20. + (NSString *)reuseId {
  21. return @"RAPhotoCell";
  22. }
  23. + (void)regist2TableView:(UITableView *)tableView {
  24. if (tableView == nil) {
  25. return;
  26. }
  27. [tableView registerNib:[UINib nibWithNibName:@"RAPhotoCell" bundle:nil] forCellReuseIdentifier:self.reuseId];
  28. }
  29. #pragma mark - Super
  30. - (void)awakeFromNib {
  31. [super awakeFromNib];
  32. // Initialization code
  33. [RAPhotoItemCell regist2CollectionView:self.photoCollectionView];
  34. }
  35. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  36. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  37. }
  38. return self;
  39. }
  40. - (void)prepareForReuse {
  41. [super prepareForReuse];
  42. self.model = nil;
  43. }
  44. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  45. [super setSelected:selected animated:animated];
  46. // Configure the view for the selected state
  47. }
  48. #pragma mark - Setter
  49. - (void)setModel:(RAPhotoModel *)model {
  50. _model.delegate = nil;
  51. _model = model;
  52. _model.delegate = self;
  53. self.photoLayout.delegate = _model;
  54. [self refreshUI];
  55. }
  56. #pragma mark - Getter
  57. - (RAPhotoLayout *)photoLayout {
  58. if (!_photoLayout) {
  59. _photoLayout = [[RAPhotoLayout alloc] init];
  60. }
  61. return _photoLayout;
  62. }
  63. #pragma mark - Model Delegate
  64. - (void)refreshUI {
  65. NSString *title = _model.title;
  66. BOOL required = _model.required;
  67. self.titleLabel.text = title;
  68. self.requiredLabel.hidden = !required;
  69. [self.photoCollectionView reloadData];
  70. }
  71. - (void)unbind {
  72. _model = nil;
  73. [self refreshUI];
  74. }
  75. #pragma mark - CollectionView DataSource
  76. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  77. return 1;
  78. }
  79. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  80. NSInteger count = self.model.photos.count;
  81. return count;
  82. }
  83. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  84. RAPhotoItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:RAPhotoItemCell.reuseId forIndexPath:indexPath];
  85. RAPhotoItemModel *model = [self.model.photos objectAtIndex:indexPath.row];
  86. cell.model = model;
  87. return cell;
  88. }
  89. #pragma mark - CollectionView Delegate
  90. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  91. }
  92. @end