简体   繁体   English

SwiftUI 应用程序因“尝试将第 2 行插入第 0 部分,但更新后第 0 部分中只有 2 行”错误而崩溃

[英]SwiftUI app crash with “attempt to insert row 2 into section 0, but there are only 2 rows in section 0 after the update” error

My app started crashing randomly during launch with below error.我的应用程序在启动期间开始随机崩溃并出现以下错误。 Sometimes it starts and sometimes it crashes.有时它会启动,有时它会崩溃。 How can I investigate this bug?我该如何调查这个错误? Any help appreciated任何帮助表示赞赏

2021-06-21 09:44:44.940545+0200 APP[18897:3547429] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 2 into section 0, but there are only 2 rows in section 0 after the update'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001186ebfba __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x0000000118595ff5 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001186ebde3 +[NSException raise:format:] + 0
    3   Foundation                          0x000000010ffa88e7 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   UIKitCore                           0x00000001245098a3 -[UITableView _endCellAnimationsWithContext:] + 9269
    5   UIKitCore                           0x0000000124524ff7 -[UITableView endUpdatesWithContext:] + 116
    6   UIKitCore                           0x00000001245251c9 -[UITableView _performBatchUpdates:withContext:completion:] + 253
    7   UIKitCore                           0x00000001245252af -[UITableView performBatchUpdates:completion:] + 97
    8   SwiftUI                             0x000000011527a801 $s7SwiftUI25UpdateCoalescingTableView33_BFB370BA5F1BADDC9D83021565761A49LLC19performBatchUpdates_10completionyyycSg_ySbcSgtF + 378
    9   SwiftUI                             0x000000011527a8da $s7SwiftUI25UpdateCoalescingTableView33_BFB370BA5F1BADDC9D83021565761A49LLC19performBatchUpdates_10completionyyycSg_ySbcSgtFTo + 175
    10  SwiftUI                             0x000000011527d31d $s7SwiftUI19ListCoreCoordinator33_BFB370BA5F1BADDC9D83021565761A49LLC17updateUITableView_2to11transactionySo0mN0C_xAA11TransactionVtF14performUpdatesL_yyAA0cD10DataSourceRzAA16SelectionManagerR_0V5ValueQy_AORtzr0_lF + 1594
    11  SwiftUI                             0x0000000115623652 $sIg_Ieg_TR + 12
    12  SwiftUI                             0x0000000115623668 $sIeg_IyB_TR + 14
    13  UIKitCore                           0x0000000124856bb9 +[UIView(Animation) performWithoutAnimation:] + 84
    14  SwiftUI                             0x000000011527dc6f $s7SwiftUI19ListCoreCoordinator33_BFB370BA5F1BADDC9D83021565761A49LLC17updateUITableView_2to11transactionySo0mN0C_xAA11TransactionVtFyycfU_ + 467
    15  SwiftUI                             0x0000000115166eb7 $sIeg_ytIegr_TR + 12
    16  SwiftUI                             0x00000001152851cf $sIeg_ytIegr_TRTA + 17
    17  SwiftUI                             0x000000011528899f $sIeg_ytIegr_TRTA.42 + 9
    18  SwiftUI                             0x0000000115150ec4 $s7SwiftUI6UpdateO3endyyFZ + 433
    19  SwiftUI                             0x0000000114fa83fd $sSo9NSRunLoopC7SwiftUIE14flushObserversyyFZ + 148
    20  SwiftUI                             0x0000000114fa8367 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_yyXEfU_ + 9
    21  SwiftUI                             0x0000000114fa35fe $ss5Error_pIgzo_ytsAA_pIegrzo_TR95$sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_yyXEfU_Tf3npf_n + 14
    22  libswiftObjectiveC.dylib            0x0000000119a9603e $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 46
    23  SwiftUI                             0x0000000114fa8356 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_ + 35
    24  SwiftUI                             0x0000000114fa8459 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_To + 43
    25  CoreFoundation                      0x0000000118658d31 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    26  CoreFoundation                      0x0000000118653542 __CFRunLoopDoObservers + 541
    27  CoreFoundation                      0x0000000118653af5 __CFRunLoopRun + 1129
    28  CoreFoundation                      0x00000001186531a7 CFRunLoopRunSpecific + 567
    29  GraphicsServices                    0x000000011c844d85 GSEventRunModal + 139
    30  UIKitCore                           0x000000012430c4df -[UIApplication _run] + 912
    31  UIKitCore                           0x000000012431139c UIApplicationMain + 101
    32  1A-Client                           0x000000010485fb5b main + 75
    33  libdyld.dylib                       0x0000000119e1cbbd start + 1
    34  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 2 into section 0, but there are only 2 rows in section 0 after the update'
terminating with uncaught exception of type NSException
CoreSimulator 772.1 - Device: iPhone 12 (6C4D1499-EBAC-4ED6-9C38-7DB0EB0C63E9) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12

I've fixed this crash by forcing section rewrite on every view refresh.我通过在每次视图刷新时强制部分重写来修复此崩溃。 It looks not optimal but the problems seems to be problem with SwiftUI view update cycle它看起来不是最佳的,但问题似乎是 SwiftUI 视图更新周期的问题

Section {
    content()
}
.id(UUID())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “尝试将第0行插入第0部分,但更新后第0部分只有0行”错误 - “Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” Error Swift-“尝试将第0行插入第0节,但更新后第0节只有0行” - Swift - “attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” “尝试将第0行插入第0部分,但更新后第0部分只有0行” - 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' 尝试将第0行插入第0部分,但更新后第0部分只有0行 - attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update 尝试将第 3 行插入第 0 节,但更新后第 0 节中只有 3 行 - attempt to insert row 3 into section 0, but there are only 3 rows in section 0 after the update 拖放时出现错误“尝试将第 4 行插入第 1 节,但更新后第 1 节中只有 4 行” - Getting an error "attempt to insert row 4 into section 1, but there are only 4 rows in section 1 after the update" while drop and drag 尝试插入行时“尝试将第 0 行插入第 0 节,但更新后第 0 节中只有 0 行” - "attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update" when trying to insert row 在表中插入一行时,“试图将第0行插入第0部分,但更新后第0部分只有0行” - 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' when inserting a row into a table 'NSInternalInconsistencyException',原因:“试图将第0行插入第0节,但更新后第0节只有0行” - 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' 'NSInternalInconsistencyException',原因:“试图将第4行插入第0节,但更新后第0节只有4行” - 'NSInternalInconsistencyException', reason: 'attempt to insert row 4 into section 0, but there are only 4 rows in section 0 after the update'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM