我正在尝试使用 insertRowsAtIndexPaths 以便可以插入表格行。我收到此错误:
*** 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).'
我正在尝试做的是动态修改部分中的行数以尝试纠正问题:
NSArray *indexPathIndex = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil];
[myTableView beginUpdates];
//***** HERE I AM TRYING TO DYNAMICALLY INCREASE NUMBER OF ROWS
[myTableView numberOfRowsInSection:1];
////////////////////////////////////////////////////////////
[myTableView insertRowsAtIndexPaths:indexPathIndex withRowAnimation:UITableViewRowAnimationTop];
[myTableView endUpdates];
最初,我在节中的行数是 0。我尝试增加这个数字以解决上述错误,但是代码 [myTableView numberOfRowsInSection:1] 似乎没有效果。
有人可以建议我如何解决这个问题吗?
谢谢你,维克多。