在uitableviewcell中的集合视图中添加属性

时间:2016-05-20 10:11:40

标签: ios objective-c iphone uitableview

我正在创建一个tableView,里面有collectionView。

我做了什么: 1.在控制器内创建一个表视图。 2.创建一个自定义tableViewCell,其中包含collectionView并为其提供标记 3.创建了一个自定义collectionViewcell。

现在我使控制器成为collectionView和tableView的委托和数据源。

现在tableView应该有多个tableViewcells,每个tableViewCell都有CollectionView

一个tableViewCell有一个部分。 问题: -

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

self.arrayModel = self.SlotsArray[indexPath.section];
}

但是这里有一个问题:让我说我的屏幕大小显示两个tableViewcell,然后首先调用tableCells的所有方法,然后调用collectionView的所有方法,而我希望在创建tableViewcell的第一部分之后,它应该调用collectionView方法并创建它。然后转到tableView方法make第2部分,然后创建它的collectionView。

有没有做到这一点。

我在网上读到的东西,我必须继承CollectionView并添加属性索引,然后在将viewcontroller设置为委托和数据源的同时,也设置索引。

但我已经创建了CollectionView By nib并通过" TAG"将其添加到tableCell类中。

self.imageCollectionView = [self.contentView viewWithTag:2511];

你能告诉我怎样才能实现这个目标?

2 个答案:

答案 0 :(得分:1)

在您的情况下,您应该有一个表格视图,包含单元格。每个单元格内部都有一个集合视图。

表格视图单元格的数量将等于数据源的数量。众所周知,表视图单元格将逐个创建,并为每个单元格分配一个数据源,用于填充集合视图(位于每个单元格内)。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    CategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifierCategory forIndexPath:indexPath];

    NSArray *arrVideos = [parentArray objectAtIndex:indexPath.row];
    [cell setCollectionData:arrVideos];

    return cell;
}

现在,在该表视图单元类中,实现setCollectionData方法来填充其集合视图:

- (void)setCollectionData:(NSArray *)collectionData 
{
    self.arrCollectionData = collectionData;
    [self.yourCollectioView reloadData];
}

现在,每个收集单元格都将从此数组中提取:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    VideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifierVideo forIndexPath:indexPath];
    NSDictionary *_video = [self.arrCollectionData objectAtIndex:[indexPath row]];

    // Use this dictionary 

    [cell.lblVideoTitle setText:_video.title];

    ––––––––––
    ––––––––––

    return cell;
}

参考以下图片:

enter image description here

希望它可以帮助你!!!

答案 1 :(得分:1)

相关问题