gpt4 book ai didi

ios - UICollectionView 断言失败

转载 作者:行者123 更新时间:2023-11-30 11:07:42 26 4
gpt4 key购买 nike

我在 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()

崩溃日志是:

*** Assertion failure in -[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

关于ios - UICollectionView 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52518645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com