草庐IT

objective-c - NSInternalInconsistencyException',原因 : 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'

coder 2023-04-26 原文

我正在使用 UITableViewController 并在更新 tableView 时收到此错误。以下是我的代码:

当我执行点击事件时会发生这种情况:

[timeZoneNames insertObject:@"HELLO" atIndex:0];  
[self.tableView beginUpdates];   
NSArray *insertIndexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];

我尝试查找苹果文档,但没有帮助。

谢谢, 阿比

最佳答案

我忘记正确设置数据源导出时遇到了这个错误。

如果您看到此错误,请检查您是否明确设置了 TableView 委托(delegate)和数据源:

  • 转到您的界面构建器并使用“表格 View ”查看 View

  • cmd + 右键单击​​从“表格 View ”图标拖动(您应该看到一条蓝线)到文件的标题图标,在 xcode 6 中它旁边有一个黄色图标。

  • 松开鼠标,您应该会看到委托(delegate)和数据源选项。

  • 选择“数据源”

您的 table 现在应该已正确接线。

关于objective-c - NSInternalInconsistencyException',原因 : 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11706254/

有关objective-c - NSInternalInconsistencyException',原因 : 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'的更多相关文章

随机推荐