ios - 在 uitableviewcell 内的 Collection View 中添加属性

标签 ios objective-c iphone uitableview

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

我做了什么 :
1. 在 Controller 内创建了一个表格 View 。
2.创建了一个自定义tableViewCell,其中包含collectionView并为其提供标签
3.创建了一个自定义collectionViewcell。

现在我将 Controller 设置为 collectionView 和 tableView 的委托(delegate)和数据源。

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

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

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

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

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

有没有办法做到这一点。

我在网上读到的某个地方,我必须继承 CollectionView 并添加一个属性索引,然后在将 viewcontroller 设置为委托(delegate)和数据源时,也设置索引。

但是我已经通过 nib 创建了 CollectionView 并通过“TAG”将其添加到 tableCell 类中
self.imageCollectionView = [self.contentView viewWithTag:2511];

你能告诉我怎样才能做到这一点吗?

最佳答案

在你的情况下,你应该有一个表格 View ,有单元格。每个单元格内部都有一个 Collection View 。

表格 View 单元格的数量将等于您的数据源的数量。众所周知,表格 View 单元格将被一个一个地创建,并为每个单元格分配一个数据源,该数据源将用于填充您的 Collection View (位于每个单元格内)。

- (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;
}

现在,在该 TableView 单元类中,实现 setCollectionData填充其 Collection View 的方法:
- (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

希望对你有帮助!!!

关于ios - 在 uitableviewcell 内的 Collection View 中添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37343959/

相关文章:

objective-c - 如何在 iOS swift 中处理 NSDictionary 作为返回类型?

iphone - iOS - 将大多数对象创建为单例是正确的选择吗?

ios - UISearchBar - ReturnKeyType 不适用于 iOS 8

iphone - Storyboard中的 Xcode 4.2 错误

iphone - SQLite3 COUNT 不正确

ios - GPUImageFilterGroup 正在返回黑色图像

iphone - 如何将 UIControl 添加到 UIScrollView contentView?

ios - 在iOS中使用UIDocumentIntractionController将图像共享到Whatsapp

ios - 如何在 Core Data 中保存有关系的实体

iOS : passing data between viewController (destination embedded in a NavigationController)