【发布时间】:2017-10-19 16:56:15
【问题描述】:
根据 crashlytics,一些用户遇到了崩溃。这就是崩溃所说的。
致命异常:NSInternalInconsistencyException 尝试插入 第 0 行到第 0 节,但在第 0 节之后只有 0 行 更新
这是我正在使用的代码。
- (void)insertArray:(NSNotification *)notification {
[self.tableView beginUpdates];
[self.arrayList insertObject:person atIndex:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.arrayList count];
}
我的表视图数据源和委托已设置,我个人从未遇到过崩溃。任何提示或建议表示赞赏。
【问题讨论】:
-
使用
numberOfRowsInSection方法更新您的问题。 -
@rmaddy 我已经更新了。是否有可能在设置委托和数据源之前调用通知?我在 viewdidload 中设置了通知。数据源和委托是通过 IB 设置的。
-
是否可以在
self.arrayList是nil的时候调用您的insertArray:方法?这会导致您看到的错误。 -
实际上,这似乎是可能的。在很短的时间内为零。
-
这就是问题所在。在
nil上调用insertObjects仍然会留下nil。在nil上调用count会给你0。因此出现错误。
标签: ios objective-c arrays uitableview crash