123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // HomeGoodBookCell.m
- // smartRhino
- //
- // Created by niuzhen on 2020/5/20.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeGoodBookCell.h"
- #import "BookHomeSubCell.h"
- #import "HomeGoodBookCollectCell.h"
- @implementation HomeGoodBookCell
- - (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:@"BookHomeSubCell" bundle:nil] forCellWithReuseIdentifier:@"BookHomeSubCell"];
- [self.collectionView registerNib:[UINib nibWithNibName:@"HomeGoodBookCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeGoodBookCollectCell"];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- + (HomeGoodBookCell *)configCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeGoodBookCell";
- HomeGoodBookCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeGoodBookCell" owner:nil options:nil] objectAtIndex:0];
- }
- return cell;
- }
- - (void)setDataWithItem:(NSInteger)Item isUnUser:(BOOL)isUser model:(HomeSubModel *)model
- {
- self.TitleL.text = model.LabelName;
- self.model = model;
- self.type = Item % 2 == 0 ? 0 : 1;
- if (self.type == 0) {
- self.collectH.constant = 101.f * model.Items.count;
- UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- [self.collectionView setCollectionViewLayout:layout];
- }else{
- CGFloat H = 0.f;
- if (model.Items.count > 3) {
- if (model.Items.count % 3 == 0) {
- H = model.Items.count / 3 * 170.f;
- }else{
- H = model.Items.count / 3 * 170.f + 170.f;
- }
- }else{
- H = 170.f;
- }
- self.collectH.constant = H;
- UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
- layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
- [self.collectionView setCollectionViewLayout:layout];
- }
- [self.collectionView setContentOffset:CGPointZero animated:NO];
- [self.collectionView reloadData];
- WS(weakSelf);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.collectionView reloadData];
- });
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
- {
- return 0.f;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
- {
- return self.type == 0 ? 0.f : 15.f;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.model.Items.count;
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (self.type == 0) {
- return CGSizeMake(SCREEN_WIDTH, 101);
- }else{
- return CGSizeMake((SCREEN_WIDTH - 60) / 3, 170);
- }
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary * dict = self.model.Items[indexPath.item];
- HomeSubItemModel * smodel = [HomeSubItemModel modelWithDictionary:dict];
- if (self.type == 0) {
- BookHomeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookHomeSubCell" forIndexPath:indexPath];
- [cell setData:smodel];
- return cell;
- }else{
- HomeGoodBookCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeGoodBookCollectCell" forIndexPath:indexPath];
- [cell setData: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
|