RAPhotoItemCell.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // RAPhotoItemCell.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/10/30.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAPhotoItemCell.h"
  9. #import "RAPhotoModelDelegate.h"
  10. #import "RAPhotoItemModel.h"
  11. @interface RAPhotoItemCell () <RAPhotoModelDelegate>
  12. @property (nonatomic,strong) IBOutlet UIImageView *photoView;
  13. @end
  14. @implementation RAPhotoItemCell
  15. + (NSString *)reuseId {
  16. return @"RAPhotoItemCell";
  17. }
  18. + (void)regist2CollectionView:(UICollectionView *)collectionView {
  19. if (!collectionView) {
  20. return;
  21. }
  22. [collectionView registerNib:[UINib nibWithNibName:@"RAPhotoItemCell" bundle:nil] forCellWithReuseIdentifier:[self reuseId]];
  23. }
  24. #pragma mark - Super
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. // Initialization code
  28. self.photoView.layer.borderWidth = 0.5f;
  29. self.photoView.layer.borderColor = [UIColor lightGrayColor].CGColor;
  30. }
  31. - (void)prepareForReuse {
  32. [super prepareForReuse];
  33. self.model = nil;
  34. }
  35. #pragma mark - Setter
  36. - (void)setModel:(RAPhotoItemModel *)model {
  37. _model.delegate = nil;
  38. _model = model;
  39. _model.delegate = self;
  40. // NSLog(@"Photo Item Cell SetModel: %p %p",self,model);
  41. [self refreshUI];
  42. }
  43. #pragma mark - Model Delegate
  44. - (void)refreshUI {
  45. self.photoView.image = _model.photo;
  46. }
  47. - (void)unbind {
  48. // NSLog(@"Photo Item Cell Unbind: %p",self);
  49. _model = nil;
  50. [self refreshUI];
  51. }
  52. #pragma mark - Action
  53. - (IBAction)photoBtnClick:(UIButton *)sender {
  54. if (self.clickBlk) {
  55. self.clickBlk(self.model);
  56. }
  57. }
  58. @end