【问题标题】:dequeuing UICollectionViewCell while debugging crashes app在调试崩溃应用程序时出队 UICollectionViewCell
【发布时间】:2016-07-10 23:24:36
【问题描述】:

我正在尝试调试我的应用程序,但是当我通过 Xcode 运行它时,我遇到了一个崩溃,提示 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] 这发生在 cellForItemAtIndexPath:对于集合视图,但它仅在我调试时发生,如果我安装应用程序并在没有 Xcode 的情况下运行它,它工作正常。

这是我的代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FFSIncidentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 
    // Configure the cell 
    ...
}

【问题讨论】:

  • 如果你不能提供让问题重现的东西,那就没什么好说的了。您说您的代码以这种方式运行。证明它。
  • 也许你可以展示你的 cellForItemAtIndexPath 实现?
  • 这是我的代码... - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FFSIncidentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; // 配置单元格
  • 它在那条线上中断了,但我不知道为什么。它昨天工作,我什么都没改变,但今天,crashola。
  • 当它“崩溃”时,它不仅仅是一个方法名称。通常在调试控制台和/或 Xcode 暂停执行中有更完整的描述,直观地向您显示它停止的位置,以及原因。您可以考虑添加exception breakpoint。但是,归根结底,您的问题中没有足够的信息供我们诊断问题。

标签: ios objective-c uicollectionview


【解决方案1】:

所以我想通了,希望这对其他人有帮助。就我而言,我在 .Xib 文件中有一个 UICollectionViewCell。该单元格中有一个UIScrollView,而UIScrollView 中有一个UIViewUIView 比屏幕高,所以在 IB 中我将它从滚动视图中拉出,以便我可以看到所有内容,但我从未将它移回滚动视图的子视图。长话短说,如果你构建一个自定义的 UITableViewCell 或 UICollectionViewCell,一切都必须是 Cell 的子视图,否则,CRASH!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多