【问题标题】:UICollectionView cellForItemAtIndexPath Not Called within UITabBarControllerUICollectionView cellForItemAtIndexPath 未在 UITabBarController 中调用
【发布时间】:2014-08-17 17:53:34
【问题描述】:

我在UIViewController 中有一个UICollectionViewUIViewController 既是UICollectionView 的数据源又是委托。一切都很好,并且按预期工作。但是,当我尝试通过 Storyboard 编辑器将 UIViewController 嵌入到 UITabBarController 中时,不再调用 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 方法。

UITabBarController 中嵌入UIViewController 是我所做的唯一更改。当我删除 UITabBarController 时,一切都会按预期工作。有没有其他人见过这种行为?我错过了什么可能导致这种情况?

【问题讨论】:

  • 是否调用了其他数据源方法,例如 numberOfItems?
  • 是的,numberOfItems 被调用并正确返回。它返回一个值 > 0,所以我假设 cellForItemAtIndexPath 会被调用,但事实并非如此。
  • 您是否知道 cellForItemAtIndexPath 不是通过日志记录调用的,或者您是基于什么都没有出现而假设?
  • 记录、断点,什么都没有显示。
  • 我尝试时无法复制这个问题,所以我没有想法。

标签: ios xcode uiviewcontroller uitabbarcontroller uicollectionview


【解决方案1】:

问题是父视图控制器的调整滚动视图插入复选框已打开。这样 UICollectionView 认为它没有任何可见的单元格并且不调用 cellForItemAtIndexPath 方法。取消选中此属性将解决问题。 您可以在 Attributes Inspector -> View Controller / Layout section -> Adjust Scroll View Insets 中找到它。 取消选中,瞧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多