UICollectionView中的断言失败?

时间:2015-09-02 23:21:39

标签: ios xcode swift debugging uicollectionview

我有一些在线托管的图片,这些图片在我的warningText=regles d\’apostrofació 中被解析为UIImageView个。当我进入和退出视图时,我经常在调试器中出现崩溃和以下错误:

UICollectionViewCell

这个错误的原因是什么?我应该如何摆脱它?

更新

我观察到当我转向*** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /SourceCache/UIKit/UIKit-3347.44.2/UICollectionView.m:3870 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete item 0 from section 0 which only contains 0 items before the update' *** First throw call stack: (0x1839702d8 0x19563c0e4 0x183970198 0x184824ed4 0x188a74348 0x100150300 0x100117c4c 0x100117d88 0x18332f010 0x1848571c4 0x1847a8604 0x1847981cc 0x184859f28 0x101410f94 0x101415c28 0x1839277f8 0x1839258a0 0x1838512d4 0x18d2a76fc 0x18844ef40 0x10011a1d4 0x195ce6a08) 时发生崩溃,并在任何单元加载之前快速返回..但由于这个原因它不应该崩溃。我该如何解决这个问题?

这是我的cellForIndex ..方法

collectionView

1 个答案:

答案 0 :(得分:0)

尝试打破reloadItems块

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! MyCollectionViewCell
        // Configure the cell
        let book = self.books[indexPath.row]
        let coverImage = book.coverImage
        if coverImage == nil {
            book.fetchCoverImage({ (image, error) -> Void in
                if collectionView != nil { // <--- something like this. I'm not sure. Just take the idea: try to check before reload.
                    collectionView.reloadItemsAtIndexPaths([indexPath])
                }
            })
        } else {
            let imageView = cell.imageView
            imageView.image = book.coverImage
        }
        return cell
    }