在UITableView上使用- (void)beginUpdates
和- (void)endUpdates
时,您是否必须对呼叫中的数据源进行更改?UITableView开始/结束更新
即
如果我有一个名为NSMutableArray
驾驶dataSource
我tableView
我能做到这一点...
// edit the actual data first
[dataSource addObject:@"Blah"];
// now update the table
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:dataSource.count - 1 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
还是有必要做......
[self.tableView beginUpdates];
[dataSource addObject:@"Blah"];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:dataSource.count - 1 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
刚问,因为我有几个地方我正在更新,我可能会将公共代码带出一个函数。
但只有当我可以更新外部的更新电话。
我应该在哪里添加这些代码行 - 在viewdidload中?或cellforrowatindexpath?或任何其他方法? –
这是非常重要的“你必须确保你在同一线程中更新数据源” – Siyavash
@Siyavash我该怎么做?我有几个代表更新数据源,如何确保在同一个线程中更新它们。 – titan