gpt4 book ai didi

ios - 无效更新 : invalid number of rows in section 0

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:42:25 24 4
gpt4 key购买 nike

当我尝试在列表中删除或添加对象时遇到问题

错误:

2014-09-04 10:59:03.815 DeleteListTest[2781:60b] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:13682014-09-04 10:59:03.856 DeleteListTest[2781:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'*** First throw call stack:(    0   CoreFoundation                      0x01b581e4 __exceptionPreprocess + 180    1   libobjc.A.dylib                     0x018d78e5 objc_exception_throw + 44    2   CoreFoundation                      0x01b58048 +[NSException raise:format:arguments:] + 136    3   Foundation                          0x014b74de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116    4   UIKit                               0x0066ff63 -[UITableView _endCellAnimationsWithContext:] + 13402    5   UIKit                               0x0067fcea -[UITableView endUpdatesWithContext:] + 51    6   UIKit                               0x0067fd18 -[UITableView endUpdates] + 41    7   DeleteListTest                      0x00002ece -[MasterViewController leaveEditMode] + 270    8   DeleteListTest                      0x0000301a -[MasterViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 202    9   UIKit                               0x006916a3 -[UITableView animateDeletionOfRowWithCell:] + 107    10  UIKit                               0x0081a595 -[UITableViewCell _swipeDeleteButtonPushed] + 70    11  libobjc.A.dylib                     0x018e9880 -[NSObject performSelector:withObject:withObject:] + 77    12  UIKit                               0x005993b9 -[UIApplication sendAction:to:from:forEvent:] + 108    13  UIKit                               0x00599345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61    14  UIKit                               0x0069abd1 -[UIControl sendAction:to:forEvent:] + 66    15  UIKit                               0x0069afc6 -[UIControl _sendActionsForEvents:withEvent:] + 577    16  UIKit                               0x0069a243 -[UIControl touchesEnded:withEvent:] + 641    17  UIKit                               0x0092f2e3 _UIGestureRecognizerUpdate + 7166    18  UIKit                               0x005d8a5a -[UIWindow _sendGesturesForEvent:] + 1291    19  UIKit                               0x005d9971 -[UIWindow sendEvent:] + 1021    20  UIKit                               0x005ab5f2 -[UIApplication sendEvent:] + 242    21  UIKit                               0x00595353 _UIApplicationHandleEventQueue + 11455    22  CoreFoundation                      0x01ae177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15    23  CoreFoundation                      0x01ae110b __CFRunLoopDoSources0 + 235    24  CoreFoundation                      0x01afe1ae __CFRunLoopRun + 910    25  CoreFoundation                      0x01afd9d3 CFRunLoopRunSpecific + 467    26  CoreFoundation                      0x01afd7eb CFRunLoopRunInMode + 123    27  GraphicsServices                    0x03a0a5ee GSEventRunModal + 192    28  GraphicsServices                    0x03a0a42b GSEventRun + 104    29  UIKit                               0x00597f9b UIApplicationMain + 1225    30  DeleteListTest                      0x00004a4d main + 141    31  libdyld.dylib                       0x0219f701 start + 1    32  ???                                 0x00000001 0x0 + 1)libc++abi.dylib: terminating with uncaught exception of type NSException(lldb) 

这是删除方法
如果(editingStyle == UITableViewCellEditingStyleDelete){
[tableTitles removeObjectAtIndex:[indexPath 行]];
[自离开编辑模式];
[[self tableView] reloadData];
有人可以帮助我吗?谢谢你:)

最佳答案

我相信您错过了电话:

[self.tableView deleteRowsAtIndexPaths:indexPath
withRowAnimation:UITableViewRowAnimationFade];

并且您不需要 reloadData 调用:

if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableTitles removeObjectAtIndex:[indexPath row]];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self leaveEditMode];

(这也会看起来更好,因为它会向用户提供视觉反馈;与 reloadData 不同)。

关于ios - 无效更新 : invalid number of rows in section 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661962/

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