// // KanKanListTableCell.m // Ifish // // Created by imac on 16/11/11. // Copyright © 2016年 lianxiang. All rights reserved. // #import "KanKanListTableCell.h" #import "ZWCollectionViewFlowLayout.h" #import "KankanListCollectionViewCell.h" #define KWidth_Scale [UIScreen mainScreen].bounds.size.width/375.0f static NSString *cellIdentifier = @"KankanListCollectionViewCell"; #import "KanKanListDataHelper.h" @interface KanKanListTableCell () { ZWCollectionViewFlowLayout *_flowLayout;//自定义layout //int a; } @end @implementation KanKanListTableCell -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.dataArray = [[NSMutableArray alloc] init]; //self.compArray = [[NSMutableArray alloc] init]; [self initContentView]; } return self; } #pragma mark- 获取直播列表 /** * 1、获取综合数据(5条距离用户最近的+5条用户最近浏览的+5条人气值最高的)直传userId,首先显示综合数据,剩下的数据按时间倒序返回,传firstResult和pageSize。 2、直播间封面默认是: 本地:http://192.168.61.128:81/room/${roomId}.png 正式云:http://app.ifish7.com/room/${roomId}.png 测试云:http://app.zhangxinyanv5.top/room/${roomId}.png */ -(void)loadDta:(NSMutableArray*)dataArray { self.dataArray = dataArray; int rowNumb = 0; rowNumb = (int)(self.dataArray.count+1)/2; CGFloat HCELL= ((280*KWidth_Scale-3*5)/2)*rowNumb + 5*rowNumb; _collectionView.frame = CGRectMake(0,0,kScreenSize.width, HCELL); [_collectionView reloadData]; } -(void)initContentView { //初始化自定义layout _flowLayout = [[ZWCollectionViewFlowLayout alloc] init]; _flowLayout.colMagrin = 5; _flowLayout.rowMagrin = 5; _flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); _flowLayout.colCount = 2; _flowLayout.degelate = self; //CGFloat AdbarH =kScreenSize.width*0.47; int rowNumb = 0; rowNumb = (int)(_dataArray.count +1)/2 ; CGFloat HCELL= ((270*KWidth_Scale-3*5)/2)*rowNumb + 5*rowNumb; _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0,0,kScreenSize.width, HCELL) collectionViewLayout:_flowLayout]; _collectionView.delegate=self; _collectionView.dataSource=self; _collectionView.bounces=NO; _collectionView.scrollEnabled=NO; _collectionView.showsVerticalScrollIndicator=NO; //指示条 _collectionView.backgroundColor=TABLE_BACKGROUD_COLOR; //_collectionView.backgroundColor = [UIColor blueColor]; [self addSubview:_collectionView]; //注册显示cell的类型 UINib *cellNib=[UINib nibWithNibName:@"KankanListCollectionViewCell" bundle:nil]; [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:cellIdentifier]; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { KankanListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; IfishKankanListModel*model = _dataArray[indexPath.row]; cell.backgroundColor = TABLE_BACKGROUD_COLOR; //cell.backgroundColor = [UIColor yellowColor]; [cell loadDataAt:indexPath withListModel:model]; return cell; } #pragma mark UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { IfishKankanListModel *listModel=_dataArray[indexPath.row]; if (self.delegate && [self.delegate respondsToSelector:@selector(TapRecommendTableCellDelegate:)]) { [self.delegate TapRecommendTableCellDelegate:listModel]; } } #pragma mark ZWwaterFlowDelegate - (CGFloat)ZWwaterFlow:(ZWCollectionViewFlowLayout *)waterFlow heightForWidth:(CGFloat)width atIndexPath:(NSIndexPath *)indexPach { return (270*KWidth_Scale-3*5)/2; } @end