ios - '无效更新 : invalid number of sections

标签 ios objective-c sections

是的,关于这个标题有很多问题。但没有人解决我的问题。 在我的应用程序中,我使用表格 View 中的部分在单击它们时显示下拉菜单。还有 UIButton 可以添加数据,它会将用户带到另一个 View 来添加。 用户添加数据并按完成后,我正在使用 dismiss view controller 返回。 所以现在没有任何部分会为新数据+1。 当用户按下该部分时,应用程序将退出并出现此错误

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (35) must be equal to the number of sections contained in the table view before the update (34), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

我的代码是

NSMutableArray *tempArr=[[NSMutableArray alloc]init];
    for(int i=0;i<username_rank.count;i++)
    {
        NSIndexPath *indexx=[NSIndexPath indexPathForRow:i inSection:btn.tag];
        [tempArr addObject:indexx];
    }

    [tournament_table insertRowsAtIndexPaths:tempArr withRowAnimation:UITableViewRowAnimationTop];

 *** First throw call stack:
(
0   CoreFoundation                      0x000000010e7b7d85 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010e22bdeb objc_exception_throw + 48
2   CoreFoundation                      0x000000010e7b7bea +[NSException raise:format:arguments:] + 106
3   Foundation                          0x000000010de75d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4   UIKit                               0x000000010fbca0dc -[UITableView _endCellAnimationsWithContext:] + 14140
5   UIKit                               0x000000010fbe0cf0 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 303
6   Sports Lion                         0x000000010d720c3f -[entertheden Btntap_expand:] + 447
7   UIKit                               0x000000010fa9ca8d -[UIApplication sendAction:to:from:forEvent:] + 92
8   UIKit                               0x000000010fc0fe67 -[UIControl sendAction:to:forEvent:] + 67
9   UIKit                               0x000000010fc10143 -[UIControl _sendActionsForEvents:withEvent:] + 327
10  UIKit                               0x000000010fc0f263 -[UIControl touchesEnded:withEvent:] + 601
11  UIKit                               0x000000010ff84c52 _UIGestureRecognizerUpdate + 10279
12  UIKit                               0x000000010fb0f48e -[UIWindow _sendGesturesForEvent:] + 1137
13  UIKit                               0x000000010fb106c4 -[UIWindow sendEvent:] + 849
14  UIKit                               0x000000010fabbdc6 -[UIApplication sendEvent:] + 263
15  UIKit                               0x000000010fa95553 _UIApplicationHandleEventQueue + 6660
16  CoreFoundation                      0x000000010e6dd301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17  CoreFoundation                      0x000000010e6d322c __CFRunLoopDoSources0 + 556
18  CoreFoundation                      0x000000010e6d26e3 __CFRunLoopRun + 867
19  CoreFoundation                      0x000000010e6d20f8 CFRunLoopRunSpecific + 488
20  GraphicsServices                    0x0000000113250ad2 GSEventRunModal + 161
21  UIKit                               0x000000010fa9af09 UIApplicationMain + 171
22  Sports Lion                         0x000000010d77050f main + 111
23  libdyld.dylib                       0x0000000111d4c92d start + 1
24  ???                                 0x0000000000000001 0x0 + 1

) libc++abi.dylib:以 NSException 类型的未捕获异常终止

谢谢

最佳答案

每当数据源发生变化时,您应该重新加载 TableView 。 所以你可以调用 [your TableView reloadData] 方法。

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

相关文章:

ios - Swiftui 似乎无法与 Cocoapods 和 Firebase 一起正常工作

objective-c - 使用 ARC 重新分配对象

objective-c - 如何使用 Facebook iOS SDK 在照片中标记用户?

swift - 如何在 UITableView 中有条件地分割数据模型?

c - 如何为数据预留一个固定的flash section?

带有部分的站点地图中的 anchor 链接

ios - 动画播放与否取决于链接动画的 animationRepeatCount

php - 从 iOS 应用程序发布数组以通过 PHP 文件在数据库中输入值

ios - 下载JSON数据,然后重新加载 Collection View

objective-c - 未调用 mapViewWillStartLoadingMap