| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- //
- // RAPhotoCell.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/10/30.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RAPhotoCell.h"
- #import "RAPhotoItemCell.h"
- #import "RAPhotoModel.h"
- #import "RAPhotoModelDelegate.h"
- #import "RAPhotoLayout.h"
- @interface RAPhotoCell ()<UICollectionViewDelegate,UICollectionViewDataSource,RAPhotoModelDelegate>
- @property (nonatomic,strong) IBOutlet UILabel *titleLabel;
- @property (nonatomic,strong) IBOutlet UILabel *requiredLabel;
- @property (nonatomic,strong) IBOutlet UICollectionView *photoCollectionView;
- @property (nonatomic,strong) RAPhotoLayout *photoLayout;
- @end
- @implementation RAPhotoCell
- + (NSString *)reuseId {
- return @"RAPhotoCell";
- }
- + (void)regist2TableView:(UITableView *)tableView {
- if (tableView == nil) {
- return;
- }
-
- [tableView registerNib:[UINib nibWithNibName:@"RAPhotoCell" bundle:nil] forCellReuseIdentifier:self.reuseId];
- }
- #pragma mark - Super
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
-
- [RAPhotoItemCell regist2CollectionView:self.photoCollectionView];
- self.photoCollectionView.collectionViewLayout = self.photoLayout;
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- }
- return self;
- }
- - (void)prepareForReuse {
- [super prepareForReuse];
-
- self.model = nil;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- #pragma mark - Setter
- - (void)setModel:(RAPhotoModel *)model {
- // NSLog(@"CollectionCell %p %p %p",self,_model,model);
- _model.delegate = nil;
- _model = model;
- _model.delegate = self;
-
- [self refreshUI];
- }
- #pragma mark - Getter
- - (RAPhotoLayout *)photoLayout {
- if (!_photoLayout) {
- _photoLayout = [[RAPhotoLayout alloc] init];
- }
- return _photoLayout;
- }
- #pragma mark - Model Delegate
- - (void)refreshUI {
- // NSLog(@"CollectionCell refreshUI %p %p",self,_model);
- NSString *title = _model.title;
- BOOL required = _model.required;
-
- self.titleLabel.text = title;
- self.requiredLabel.hidden = !required;
-
- self.photoLayout.delegate = _model;
- [self.photoCollectionView reloadData];
- }
- - (void)unbind {
- _model = nil;
- // [self refreshUI];
- }
- #pragma mark - CollectionView DataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- NSInteger count = self.model.photos.count;
- return count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- RAPhotoItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:RAPhotoItemCell.reuseId forIndexPath:indexPath];
- RAPhotoItemModel *model = [self.model.photos objectAtIndex:indexPath.row];
- cell.model = model;
-
- __weak typeof(self) weakSelf = self;
- cell.clickBlk = ^(RAPhotoItemModel *model) {
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
- [strongSelf clickItem:model];
- }
- };
-
- return cell;
- }
- #pragma mark - CollectionView Delegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [self clickItem:[self.model photoItemAtIndex:indexPath.item]];
- }
- #pragma mark - Action
- - (void)clickItem:(RAPhotoItemModel *)model {
- if (self.delegate && [self.delegate respondsToSelector:@selector(photoCell:didClickPhotoItem:)]) {
- [self.delegate photoCell:self didClickPhotoItem:model];
- }
- }
- @end
|