首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwiftUI应用程序崩溃,并显示“尝试将第2行插入区段0,但更新后区段0中只有2行”错误

SwiftUI应用程序崩溃,并显示“尝试将第2行插入区段0,但更新后区段0中只有2行”错误
EN

Stack Overflow用户
提问于 2021-06-21 15:51:37
回答 1查看 225关注 0票数 0

我的应用程序在启动时开始随机崩溃,错误如下。有时它会启动,有时会崩溃。我如何调查这个bug?感谢您的任何帮助

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-06-21 18:19:02

我已经修复了这个崩溃,强制在每次视图刷新时重写部分。它看起来并不是最优的,但问题似乎出在SwiftUI视图更新周期上

代码语言:javascript
复制
Section {
    content()
}
.id(UUID())
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68064247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档