[英]add property in collection view inside uitableviewcell
我正在創建一個tableView,里面有collectionView。
我做了什么:1.在控制器內創建一個表視圖。 2.創建一個帶有collectionView的自定義tableViewCell並為其提供標簽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方法的第2部分,然后創建其collectionView。
有沒有辦法做到這一點。
我在網上閱讀的某個地方,我將必須繼承CollectionView並添加一個屬性索引,然后將viewcontroller設置為委托和數據源,同時還要設置索引。
但是我已經通過筆尖創建了CollectionView,並通過“ TAG”將其添加到tableCell類中
self.imageCollectionView = [self.contentView viewWithTag:2511];
你能告訴我如何做到這一點嗎?
在您的情況下,您應該具有一個表格視圖,並具有單元格。 每個單元內部都有一個集合視圖。
表格視圖單元格的數量將等於您的數據源的數量。 眾所周知,表視圖單元將一個一個地創建,並為每個單元分配一個數據源,該數據源將用於填充您的集合視圖(位於每個單元內部)。
- (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;
}
請參考下圖:
希望對您有幫助!
您可以對此進行查看,它肯定會幫助您在uitableviewcell中實現水平滾動收集視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.