123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // LDTodayModelView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/11.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDTodayModelView.h"
- #import "LDModelCollectionCell.h"
- static NSString *KModelViewCell = @"modelViewCell";
- @interface LDTodayModelView ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- {
- NSArray *dataArr;
- NSInteger _num;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation LDTodayModelView
- - (void)setGoodData:(NSArray *)data {
- dataArr = data.mutableCopy;
- [self.collectionView reloadData];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- _num = 1;
- self.layer.masksToBounds = YES;
- [self initSubView];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame titleNumOfLine:(NSInteger)num{
- self = [super initWithFrame:frame];
- if (self) {
- _num = num;
- self.layer.masksToBounds = YES;
- [self initSubView];
- }
- return self;
- }
- - (void)initSubView {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) collectionViewLayout:flowLayout];
- flowLayout.minimumLineSpacing = 5;
- flowLayout.minimumInteritemSpacing = 0;
- flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- self.collectionView.backgroundColor = [UIColor whiteColor];
- [self.collectionView registerClass:[LDModelCollectionCell class] forCellWithReuseIdentifier:KModelViewCell];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self addSubview:self.collectionView];
- }
- #pragma mark ---- UICollectionView Delegate ------
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake((self.width-Fitsize(20))/3.0f, self.collectionView.height);
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return dataArr.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- LDChildGoodModel *model = dataArr[indexPath.row];
- LDModelCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KModelViewCell forIndexPath:indexPath];
- cell.model = model;
- cell.titleLabel.numberOfLines = _num;
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- return UIEdgeInsetsMake(0, 5, 0, 0);
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- LDChildGoodModel *model = dataArr[indexPath.row];
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *request = [[DetailRequestModel alloc] initWithChildModel:model];
- detail.requestModel = request;
- if (self.isOhterPage) {
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:self.Id source:CategoryRecommendAction];
- detail.eventModel = evevtModel;
- }else {
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:self.Id source:AdvFourListGoodsAction];
- detail.eventModel = evevtModel;
- }
-
- [[self currentViewController].navigationController pushViewController:detail animated:YES];
- if (self.isOhterPage) {
- [MobClick event:CategoryRecommend label:self.name];
- }else {
- [MobClick event:TodayClickGoods label:self.name];
- }
-
- }
- - (UIViewController *)currentViewController{
-
- UIViewController * currVC = nil;
- UIWindow *window = [UIApplication sharedApplication].delegate.window;
- UIViewController * Rootvc = window.rootViewController;
-
- do {
- if ([Rootvc isKindOfClass:[UINavigationController class]]) {
- UINavigationController * nav = (UINavigationController *)Rootvc;
- UIViewController * v = [nav.viewControllers lastObject];
- currVC = v;
- Rootvc = v.presentedViewController;
- continue;
- }else if([Rootvc isKindOfClass:[UITabBarController class]]){
- UITabBarController * tabVC = (UITabBarController *)Rootvc;
- currVC = tabVC;
- Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
- continue;
- }
- } while (Rootvc!=nil);
-
- return currVC;
- }
- @end
|