UICollectionView上的断言失败

时间:2018-09-26 13:13:40

标签: ios swift uicollectionview uicollectionviewcell

我在我的iOS应用程序中使用UICollectionView,有时该应用程序在我的collectionview上因声明错误而崩溃。我对其进行了调试,这似乎是一个UIKit断言(这不是节数或单元格数的问题)

有人已经遇到这种错误吗?我找不到解决方案。

我向您展示我的代码:

            var indexPaths : [IndexPath] = [IndexPath]()

            for issue in issuesLoaded
            {
                let position : Int = IssueManager.sharedInstance.getPositionOfIssue(rubricId: self.rubricId!,
                                                                                    contentId: issue.contentId!)

                let indexPath : IndexPath = IndexPath(row: position, section: 0)
                indexPaths.append(indexPath)

                if(position <= self.issues.count - 1)
                {
                    self.issues.insert(issue, at: position)
                }
                else
                {
                    self.issues.append(issue)
                }
            }

            self.collectionView.insertItems(at: indexPaths)

            self.isLoading = false
            self.collectionView.collectionViewLayout.invalidateLayout()

崩溃日志是:

  

***-[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:]中的断言失败,   /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.54.4/UICollectionView.m:5867

还有stackTrace:

> Thread 1 Queue : com.apple.main-thread (serial)
> #0    0x00000001833a92e0 in __pthread_kill ()
> #1    0x000000018354a288 in pthread_kill$VARIANT$mp ()
> #2    0x0000000183317d0c in abort ()
> #3    0x0000000103c68b0c in uncaught_exception_handler ()
> #4    0x00000001839231c8 in __handleUncaughtException ()
> #5    0x0000000182adc8c8 in _objc_terminate() ()
> #6    0x0000000182acd37c in std::__terminate(void (*)()) ()
> #7    0x0000000182accccc in __cxa_throw ()
> #8    0x0000000182adc720 in objc_exception_throw ()
> #9    0x0000000183922bf8 in +[NSException raise:format:arguments:] ()
> #10   0x0000000184312fa0 in -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] ()
> #11   0x000000018d67b240 in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:]
> ()
> #12   0x000000018d679844 in -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] ()
> #13   0x000000018d679434 in -[UICollectionView insertItemsAtIndexPaths:] ()
> #14   0x00000001027a1f8c in closure #1 in ContentViewCell.loadNextIssues() at
> /Users/username/Project/Views/ContentViewCell.swift:167
> #15   0x00000001029ddc3c in closure #1 in closure #1 in closure #2 in closure #1 in closure #1 in closure #1 in
> IssueManager.getIssueForContentIds(contentIds:completionHandler:) at
> /Users/username/Project/Manager/IssueManager.swift:684
> #16   0x0000000102787b68 in thunk for @escaping @callee_guaranteed () -> () ()
> #17   0x00000001049c11dc in _dispatch_call_block_and_release ()
> #18   0x00000001049c119c in _dispatch_client_callout ()
> #19   0x00000001049c5d2c in _dispatch_main_queue_callback_4CF ()
> #20   0x00000001838cb070 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
> #21   0x00000001838c8bc8 in __CFRunLoopRun ()
> #22   0x00000001837e8da8 in CFRunLoopRunSpecific ()
> #23   0x00000001857ce020 in GSEventRunModal ()
> #24   0x000000018d808758 in UIApplicationMain ()
> #25   0x000000010299d1a4 in main at /Users/username/Project/AppDelegate.swift:15

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

每次插入后尝试重新加载collectionView