HomeBigshotCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // HomeBigshotCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/13.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeBigshotCell.h"
  9. #import "HomeBigshotCollectCell.h"
  10. #import "HomeBigshotListCell.h"
  11. @interface HomeBigshotCell()
  12. @property (nonatomic, assign) NSInteger type;
  13. @property (nonatomic, strong) HomeSubModel * model;
  14. @end
  15. @implementation HomeBigshotCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. self.collectionView.delegate = self;
  19. self.collectionView.dataSource = self;
  20. self.collectionView.showsVerticalScrollIndicator = NO;
  21. self.collectionView.showsHorizontalScrollIndicator = NO;
  22. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotCollectCell"];
  23. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotListCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotListCell"];
  24. }
  25. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  26. [super setSelected:selected animated:animated];
  27. // Configure the view for the selected state
  28. }
  29. + (HomeBigshotCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  30. static NSString *cellIdentifer = @"HomeBigshotCell0";
  31. HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  32. if (cell == nil) {
  33. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:0];
  34. }
  35. return cell;
  36. }
  37. + (HomeBigshotCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  38. static NSString *cellIdentifer = @"HomeBigshotCell1";
  39. HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  40. if (cell == nil) {
  41. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:1];
  42. }
  43. return cell;
  44. }
  45. //- (void)setDatatype:(NSInteger)type array:(NSArray *)array
  46. //{
  47. // self.type = type;
  48. // self.model = array;
  49. // if (self.type == 0) {
  50. // self.collectionView.scrollEnabled = YES;
  51. // UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  52. // layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  53. // layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
  54. // [self.collectionView setCollectionViewLayout:layout];
  55. // [self.collectionView setContentOffset:CGPointZero animated:NO];
  56. // }else{
  57. // self.height.constant = 20 * 110.f;
  58. // self.collectionView.scrollEnabled = NO;
  59. // UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  60. // layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  61. // layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  62. // [self.collectionView setCollectionViewLayout:layout];
  63. // [self.collectionView setContentOffset:CGPointZero animated:NO];
  64. // }
  65. // [self.collectionView reloadData];
  66. //}
  67. - (void)setDatatype:(NSInteger)type model:(HomeSubModel *)model
  68. {
  69. self.CellTitleL.text = model.LabelName;
  70. self.type = type;
  71. self.model = model;
  72. if (self.type == 0) {
  73. self.collectionView.scrollEnabled = YES;
  74. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  75. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  76. layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
  77. [self.collectionView setCollectionViewLayout:layout];
  78. [self.collectionView setContentOffset:CGPointZero animated:NO];
  79. }else{
  80. self.height.constant = model.Items.count * 110.f;
  81. self.collectionView.scrollEnabled = NO;
  82. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  83. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  84. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  85. [self.collectionView setCollectionViewLayout:layout];
  86. [self.collectionView setContentOffset:CGPointZero animated:NO];
  87. }
  88. [self.collectionView reloadData];
  89. }
  90. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  91. {
  92. return self.type == 0 ? 10.f:0.f;
  93. }
  94. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  95. {
  96. return self.type == 0 ? 0.f:0.f;
  97. }
  98. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  99. {
  100. return self.model.Items.count;
  101. }
  102. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  103. {
  104. return 1;
  105. }
  106. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. if (self.type == 0) {
  109. return CGSizeMake(130, 175);
  110. }else{
  111. return CGSizeMake(SCREEN_WIDTH, 110);
  112. }
  113. }
  114. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. if (self.type == 0) {
  117. HomeBigshotCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotCollectCell" forIndexPath:indexPath];
  118. HomeSubItemModel * sModel = self.model.Items[indexPath.item];
  119. [cell setDataModel:sModel];
  120. return cell;
  121. }else{
  122. HomeBigshotListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotListCell" forIndexPath:indexPath];
  123. HomeSubItemModel * sModel = self.model.Items[indexPath.item];
  124. [cell setDataModel:sModel];
  125. return cell;
  126. }
  127. }
  128. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  129. {
  130. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  131. NSDictionary * dict = self.model.Items[indexPath.item];
  132. HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
  133. if (self.ClickItemBlock) {
  134. self.ClickItemBlock(model);
  135. }
  136. }
  137. @end