猎豆优选

LDTodayGroupCell.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // LDTodayGroupCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/12/13.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDTodayGroupCell.h"
  9. #import "LDGroupChildGoodCell.h"
  10. #import "LDLoadAllgoodCell.h"
  11. #import "LDGoodListViewController.h"
  12. static NSString *cellID = @"cellID";
  13. static NSString *cellIDs = @"cellIDs";
  14. @interface LDTodayGroupCell ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  15. {
  16. NSArray *dataArr;
  17. NSInteger _num;
  18. }
  19. @property (nonatomic, strong) UICollectionView *collectionView;
  20. @end
  21. @implementation LDTodayGroupCell
  22. - (instancetype)initWithFrame:(CGRect)frame
  23. {
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. self.backgroundColor = [UIColor clearColor];
  27. [self initSubViews];
  28. }
  29. return self;
  30. }
  31. - (void)setGoodData:(NSArray *)data {
  32. dataArr = data.mutableCopy;
  33. [self.collectionView reloadData];
  34. }
  35. - (void)initSubViews {
  36. self.bgImgView = [[UIImageView alloc] initWithFrame:self.bounds];
  37. self.bgImgView.contentMode = UIViewContentModeScaleAspectFill;
  38. self.bgImgView.backgroundColor = [UIColor whiteColor];
  39. [self addSubview:self.bgImgView];
  40. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  41. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, Fitsize(40), self.width, Fitsize(165)) collectionViewLayout:flowLayout];
  42. flowLayout.minimumLineSpacing = Fitsize(14);
  43. flowLayout.minimumInteritemSpacing = 0;
  44. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  45. self.collectionView.backgroundColor = [UIColor clearColor];
  46. [self.collectionView registerClass:[LDGroupChildGoodCell class] forCellWithReuseIdentifier:cellID];
  47. [self.collectionView registerClass:[LDLoadAllgoodCell class] forCellWithReuseIdentifier:cellIDs];
  48. self.collectionView.delegate = self;
  49. self.collectionView.dataSource = self;
  50. self.collectionView.showsHorizontalScrollIndicator = NO;
  51. [self addSubview:self.collectionView];
  52. }
  53. #pragma mark ---- UICollectionView Delegate ------
  54. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  55. return CGSizeMake(Fitsize(115), Fitsize(160));
  56. }
  57. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  58. return 1;
  59. }
  60. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  61. return dataArr.count+1;
  62. }
  63. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  64. {
  65. return CGSizeMake(0, 0);
  66. }
  67. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  68. {
  69. return CGSizeMake(0, 0);
  70. }
  71. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  72. if (indexPath.row == dataArr.count) {
  73. LDLoadAllgoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIDs forIndexPath:indexPath];
  74. cell.backgroundColor =[UIColor whiteColor];
  75. return cell;
  76. }
  77. LDChildGoodModel *model = dataArr[indexPath.row];
  78. LDGroupChildGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  79. cell.model = model;
  80. return cell;
  81. }
  82. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  83. return UIEdgeInsetsMake(0, 10, 0, 10);
  84. }
  85. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  86. if (indexPath.row == dataArr.count) {
  87. //列表页
  88. if (self.moreClick) {
  89. self.moreClick();
  90. }
  91. return;
  92. }
  93. LDChildGoodModel *model = dataArr[indexPath.row];
  94. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  95. DetailRequestModel *request = [[DetailRequestModel alloc] initWithChildModel:model];
  96. detail.requestModel = request;
  97. [[self currentViewController].navigationController pushViewController:detail animated:YES];
  98. }
  99. - (UIViewController *)currentViewController{
  100. UIViewController * currVC = nil;
  101. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  102. UIViewController * Rootvc = window.rootViewController;
  103. do {
  104. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  105. UINavigationController * nav = (UINavigationController *)Rootvc;
  106. UIViewController * v = [nav.viewControllers lastObject];
  107. currVC = v;
  108. Rootvc = v.presentedViewController;
  109. continue;
  110. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  111. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  112. currVC = tabVC;
  113. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  114. continue;
  115. }
  116. } while (Rootvc!=nil);
  117. return currVC;
  118. }
  119. @end