// // HomeProblemTopCell.m // smartRhino // // Created by niuzhen on 2020/5/19. // Copyright © 2020 tederen. All rights reserved. // #import "HomeProblemTopCell.h" #import "HomeProblemTopCollectCell.h" #import "NSDate+Extension.h" @interface HomeProblemTopCell() @property (nonatomic, strong) NSArray * dataArray; @end @implementation HomeProblemTopCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } + (HomeProblemTopCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeProblemTopCell0"; HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:0]; } return cell; } + (HomeProblemTopCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeProblemTopCell1"; HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:1]; } return cell; } - (void)setDataListModel:(HomeSubItemModel *)model { self.TitleL.text = model.Title; [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:kPlaceHolderImage]; self.subTitleL.text = model.Summary; self.nameL.text = model.Author; self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount]; self.keL.text = @""; self.timeL.text = [NSDate getMonthAndDayWihtDate:model.CreatedDate]; } - (void)setDataModel:(BookProblemModel *)model { self.dataArray = model.ImageUrls.mutableCopy; self.collectH.constant = self.dataArray.count == 0 ? 0.f : 76.f; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; [self.collectionView registerNib:[UINib nibWithNibName:@"HomeProblemTopCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeProblemTopCollectCell"]; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView setCollectionViewLayout:layout]; [self.collectionView setContentOffset:CGPointZero animated:NO]; self.topTitleL.text = model.Title; self.topContentL.attributedText = [[NSAttributedString alloc] initWithString:model.Blocks]; [self.collectionView reloadData]; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 5.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 5.f; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(101, 76); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { NSString * imageStr = [self.dataArray objectAtIndex:indexPath.item]; HomeProblemTopCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeProblemTopCollectCell" forIndexPath:indexPath]; [cell setImageViewWithString:imageStr]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; WS(weakSelf); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES]; }); } @end