// // HomeBigshotCell.m // smartRhino // // Created by niuzhen on 2020/6/13. // Copyright © 2020 tederen. All rights reserved. // #import "HomeBigshotCell.h" #import "HomeBigshotCollectCell.h" #import "HomeBigshotListCell.h" @interface HomeBigshotCell() @property (nonatomic, assign) NSInteger type; @property (nonatomic, strong) HomeSubModel * model; @end @implementation HomeBigshotCell - (void)awakeFromNib { [super awakeFromNib]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotCollectCell"]; [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotListCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotListCell"]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } + (HomeBigshotCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeBigshotCell0"; HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:0]; } return cell; } + (HomeBigshotCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeBigshotCell1"; HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:1]; } return cell; } //- (void)setDatatype:(NSInteger)type array:(NSArray *)array //{ // self.type = type; // self.model = array; // if (self.type == 0) { // self.collectionView.scrollEnabled = YES; // UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; // layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; // layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); // [self.collectionView setCollectionViewLayout:layout]; // [self.collectionView setContentOffset:CGPointZero animated:NO]; // }else{ // self.height.constant = 20 * 110.f; // self.collectionView.scrollEnabled = NO; // UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; // layout.scrollDirection = UICollectionViewScrollDirectionVertical; // layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); // [self.collectionView setCollectionViewLayout:layout]; // [self.collectionView setContentOffset:CGPointZero animated:NO]; // } // [self.collectionView reloadData]; //} - (void)setDatatype:(NSInteger)type model:(HomeSubModel *)model { self.CellTitleL.text = model.LabelName; self.type = type; self.model = model; if (self.type == 0) { self.collectionView.scrollEnabled = YES; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); [self.collectionView setCollectionViewLayout:layout]; [self.collectionView setContentOffset:CGPointZero animated:NO]; }else{ self.height.constant = model.Items.count * 110.f; self.collectionView.scrollEnabled = NO; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView setCollectionViewLayout:layout]; [self.collectionView setContentOffset:CGPointZero animated:NO]; } [self.collectionView reloadData]; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return self.type == 0 ? 10.f:0.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return self.type == 0 ? 0.f:0.f; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.model.Items.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.type == 0) { return CGSizeMake(130, 175); }else{ return CGSizeMake(SCREEN_WIDTH, 110); } } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.type == 0) { HomeBigshotCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotCollectCell" forIndexPath:indexPath]; HomeSubItemModel * sModel = self.model.Items[indexPath.item]; [cell setDataModel:sModel]; return cell; }else{ HomeBigshotListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotListCell" forIndexPath:indexPath]; HomeSubItemModel * sModel = self.model.Items[indexPath.item]; [cell setDataModel:sModel]; return cell; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; NSDictionary * dict = self.model.Items[indexPath.item]; HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict]; if (self.ClickItemBlock) { self.ClickItemBlock(model); } } @end