本文介绍了NSInternalInconsistencyException',原因:“试图将第0行插入第0节,但更新后第0节只有0行"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITableViewController并在更新tableView时遇到此错误.下面是我的代码:

I am using UITableViewController and getting this error while updating tableView. Below is my code:

发生点击事件时会发生这种情况:

This occurs when i do a click event:

[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];

我尝试查找Apple文档,但没有帮助.

I tried looking for apple documentation but that didnt helped.

谢谢,阿比

推荐答案

我之前曾遇到过此问题.这意味着调用-insertRowsAtIndexPaths:withRowAnimation:-tableView:numberOfRowsInSection:返回0.在调用-insertRowsAtIndexPaths:withRowAnimation:之前,您需要插入模型中(请参阅: -beginUpdates )

I've ran into this problem before. It means that when -insertRowsAtIndexPaths:withRowAnimation: was called -tableView:numberOfRowsInSection: returned 0. You need to insert into the model before you call -insertRowsAtIndexPaths:withRowAnimation: (see: -beginUpdates)

更新

我想知道-tableView:numberOfRowsInSection:的返回值是多少?另外,如果只有一个更新,则不需要-beginUpdates/-endUpdates.

I wonder what the return value of -tableView:numberOfRowsInSection: is? Also, you don't need -beginUpdates/-endUpdates if you only have one update.

[timeZoneNames insertObject:@"HELLO" atIndex:0];
// Let's see what the tableView claims is the the number of rows.
NSLog(@"numberOfRowsInSection: %d", [self tableView:self.tableView numberOfRowsInSection:0]);
NSArray *insertIndexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationTop];

这篇关于NSInternalInconsistencyException',原因:“试图将第0行插入第0节,但更新后第0节只有0行"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 21:32