【问题标题】:Error while adding UICollectionView inside UITableViewCell在 UITableViewCell 中添加 UICollectionView 时出错
【发布时间】:2012-11-16 20:27:27
【问题描述】:

所以我试图在 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; 
}

我收到错误:对象不能为零。如果有人能帮助我理解错误,我将不胜感激。

【问题讨论】:

    标签: ios xcode uitableview uicollectionview


    【解决方案1】:

    我已经在我的应用程序中完成了这项工作。

    我发现子类化 UITableViewCell 要容易得多。我可以将所有 UICollectionView 设置和 UICollectionView 数据源和委托放在单元格的代码中。

    然后我提供了一个 NSArray 类型的公共属性,我将其传递到单元格中。然后,单元格使用这个数组作为它自己拥有的 UICollectionView 的数据源。

    使其更易于管理。

    【讨论】:

      【解决方案2】:

      检查你的 UICollectionViewControlle 的属性检查器的标识符值 {collectionViewID}

      编辑 [自我 addChildViewController:cv]; --> 我想你想把 cv 添加到单元格中,不是吗?

      【讨论】:

      • 那你为什么不想要self [cell addChildViewController:cv];
      • 我收到错误“UIView 没有可见的@interface 声明 addchildviewcontrolelr..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 2023-03-21
      相关资源
      最近更新 更多