怎么在TableViewCell里嵌入一个CollectionView

iOS 码拜 8年前 (2016-03-25) 1062次浏览
如题,本人不知道CollectionView德DataSource和Delegate该怎么写了,求指导
解决方案

20

#import “HomeSection1Cell.h”
#import “AddFunctionCell.h”
static NSString * const reuseIdentifier = @”AddFunctionCell”;
@implementation HomeSection1Cell
– (void)awakeFromNib {

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(88, 88)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
flowLayout.minimumLineSpacing = 0;
flowLayout.minimumInteritemSpacing = 0;

[_collection setCollectionViewLayout:flowLayout];
[_collection registerNib:[UINib nibWithNibName:@”AddFunctionCell” bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
}
#pragma -mark CollectionView DataSource
– (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.functionCount;
}
– (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
AddFunctionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
return cell;
}

10

没懂,你是要在tableview里自定义一个cell然后加上CollectionView吗?
假如是上面说的那种,那直接在tableview的数据源方法
– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@”reuseIdentifier”#> forIndexPath:indexPath];

[cell.contentView addSubview: _collection];
}
添加你写的collection就好了

10


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么在TableViewCell里嵌入一个CollectionView
喜欢 (0)
[1034331897@qq.com]
分享 (0)