【发布时间】:2011-05-11 10:44:28
【问题描述】:
我正在使用下面的代码来刷新我刚刚添加了一行的表格视图。如果表中已经至少有 1 行,则该代码适用于向表中添加一行。但是,如果它最初是一个空表,它会崩溃。
NSArray *indexPaths = [NSArray arrayWithObjects: [NSIndexPath indexPathForRow:[commentsArray count] inSection:0], nil];
[commentsTableView beginUpdates];
[commentsArray addObject:newestEntry];
[commentsTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[commentsTableView endUpdates];
[commentsTableView scrollToBottom:YES];
我得到的崩溃响应是:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
有人可以帮我吗?
【问题讨论】:
标签: uitableview row add