所以我试图在tableviewcell中显示水平可滚动的集合视图。我正在使用的代码是
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UICollectionViewController *cv = [self.storyboard instantiateViewControllerWithIdentifier:@"collectionViewID"];
cv.view.frame = cell.contentView.bounds;
[self addChildViewController:cv];
[cell.contentView addSubview:cv.view];
[cv didMoveToParentViewController:self];
return cell;
}
我收到错误:对象不能为零。如果有人能帮助我理解错误,我会很感激。
答案 0 :(得分:3)
我已在我的应用中完成此操作。
我发现继承UITableViewCell要容易得多。我可以将所有UICollectionView设置和UICollectionView数据源和委托放在单元格的代码中。
然后我提供了一个NSArray类型的公共属性,我将其传递到单元格中。然后,该单元使用此数组作为其拥有的UICollectionView的数据源。
使管理更容易。
答案 1 :(得分:0)
检查您的UICollectionViewControlle属性检查器的标识符值{collectionViewID}
EDIT [self addChildViewController:cv]; - >我想你想把cv添加到单元格中,不是吗?