![](/img/trans.png)
[英]NSInternalInconsistencyException after UITableView reloadData
[英]ReloadData after UITableView updates
我试图像这样向我的tableView添加行:
[myArray addObject:@"Apple"];
[myTableView beginUpdates];
[myTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[myTableView endUpdates];
问题在于单元格没有刷新。 textLabels与数据源数组不对应。
我通过添加以下内容解决了该问题:
[myTableView reloadData];
但这使精美的插入动画消失了。
有想法吗? 谢谢!
addObject:
将对象添加到可变数组的末尾 。 然后,在您的下一行中,告诉表格视图在表格的顶部显示新行。 除非您的数组“向后”,否则好像您是在告诉表在错误的位置“插入”一个单元格一样。
您正在将项目添加到数组的末尾,但在表的开头添加了一行。
NSString* obj = @"Apple";
[myArray addObject:obj];
[myTableView beginUpdates];
[myTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[myArray indexOfObject:obj] inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[myTableView endUpdates];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.