猎豆优选

LDTodayModelView.m 5.2KB

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