【问题标题】:Some users experiencing NSInternalInconsistencyException crash一些用户遇到 NSInternalInconsistencyException 崩溃
【发布时间】: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.arrayListnil 的时候调用您的insertArray: 方法?这会导致您看到的错误。
  • 实际上,这似乎是可能的。在很短的时间内为零。
  • 这就是问题所在。在nil 上调用insertObjects 仍然会留下nil。在nil 上调用count 会给你0。因此出现错误。

标签: ios objective-c arrays uitableview crash


【解决方案1】:

此错误表明您的数据源的 numberOfRowsInSection 返回的行数不包括新行(您仍然报告该表即使在插入后也应该有 0 行)。在执行任何单元事务之前,应更新您的数据源。

由于您自己没有经历过,似乎一定有某种情况或极端情况会阻止您的数据源正确更新。编辑您的问题并显示您的数据源方法可能会提供一些见解。

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 2017-05-14
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2016-10-16
    相关资源
    最近更新 更多