0

我正在尝试从不同的类访问 tableView 属性(在 UITableViewController 类中定义)。一旦我访问它,我需要向它发送方法

insertRowsAtIndexPaths: withRowAnimation:UITableViewRowAnimationAutomatic:

这是我的代码,但它似乎没有插入新行?

[((MainViewController *)self.presentingViewController).tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];

4

1 回答 1

0

您需要确保您的数据源也能自行修改。所以如果你插入一个新行,你需要

--tableView:numberOfRowsInSection:

比以前多返回 1,并且

--tableView:cellForRowAtIndexPath:

返回新单元格。TableView 不会为您处理这些部分。

这是您的代码应该是什么样子的粗略轮廓。

[tableView beginUpdates];
// Some code to add row to your datasource
[datasource addrow]
[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
于 2012-10-10T19:13:54.110 回答