ios - UICollectionView 上的断言失败
问题描述
我在我的 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
和堆栈跟踪:
> 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
感谢您的帮助!!
解决方案
尝试在每次插入后重新加载 collectionView
推荐阅读
- python - Django 有一个禁用的表单作为默认选择的表单
- model-view-controller - 我应该在分层架构中的哪一层放置 websocket 调用?
- sql-server - 根据临近日期执行加入
- c++ - 如何从 .pro 文件的列表中删除某些文件?
- laravel-8 - 会话数据在“升级”到 Laravel 8 后大约 4 分钟到期
- javascript - 使用 python 通过 Tor 匿名 scape javascript 信息
- c++ - 链表模板实现和运算符重载
- angular - 被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头
- gmail-api - 如何创建临时 g-mail 帐户
- python - URL 上的多次迭代