123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // 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
|