123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // LDTodayGroupCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/12/13.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDTodayGroupCell.h"
- #import "LDGroupChildGoodCell.h"
- #import "LDLoadAllgoodCell.h"
- #import "LDGoodListViewController.h"
- static NSString *cellID = @"cellID";
- static NSString *cellIDs = @"cellIDs";
- @interface LDTodayGroupCell ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- {
- NSArray *dataArr;
- NSInteger _num;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation LDTodayGroupCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor clearColor];
- [self initSubViews];
- }
- return self;
- }
- - (void)setGoodData:(NSArray *)data {
- dataArr = data.mutableCopy;
- [self.collectionView reloadData];
- }
- - (void)initSubViews {
- self.bgImgView = [[UIImageView alloc] initWithFrame:self.bounds];
- self.bgImgView.contentMode = UIViewContentModeScaleAspectFill;
- self.bgImgView.backgroundColor = [UIColor whiteColor];
- [self addSubview:self.bgImgView];
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, Fitsize(40), self.width, Fitsize(165)) collectionViewLayout:flowLayout];
- flowLayout.minimumLineSpacing = Fitsize(14);
- flowLayout.minimumInteritemSpacing = 0;
- flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- self.collectionView.backgroundColor = [UIColor clearColor];
- [self.collectionView registerClass:[LDGroupChildGoodCell class] forCellWithReuseIdentifier:cellID];
- [self.collectionView registerClass:[LDLoadAllgoodCell class] forCellWithReuseIdentifier:cellIDs];
- 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(Fitsize(115), Fitsize(160));
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-
- return dataArr.count+1;
- }
- - (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 {
- if (indexPath.row == dataArr.count) {
-
- LDLoadAllgoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIDs forIndexPath:indexPath];
- cell.backgroundColor =[UIColor whiteColor];
- return cell;
- }
- LDChildGoodModel *model = dataArr[indexPath.row];
- LDGroupChildGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
- cell.model = model;
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- return UIEdgeInsetsMake(0, 10, 0, 10);
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == dataArr.count) {
- //列表页
- if (self.moreClick) {
- self.moreClick();
- }
- return;
- }
- LDChildGoodModel *model = dataArr[indexPath.row];
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *request = [[DetailRequestModel alloc] initWithChildModel:model];
- detail.requestModel = request;
- [[self currentViewController].navigationController pushViewController:detail animated:YES];
-
- }
- - (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
|