2012-10-04 79 views
5

[tableView reloadData]影响ios中的性能?什么是[tableView reloadData]?它如何重新加载tableview?有没有其他方式来重新加载tableview?ios:[tableView reloadData]

我想添加一些行到tableview的结尾。我怎样才能做到这一点?

是什么

[self.tableView reloadData] 

[self.tableView beginUpdates]; 
[self.tableView insertRowsAtIndexPaths:insertIndexPathswithRowAnimation:UITableViewRowAnimationAutomatic]; 
[self.tableView endUpdates]; 
+2

这在[标准的地方]所有有案可稽(http://developer.apple.com/library/ios/#文档/ UserExperience /概念/ TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#// apple_ref/DOC/UID/TP40007451-CH10-SW1)。 –

+0

浏览苹果文档:https://developer.apple.com/documentation/uikit/uitableview –

回答

3

的区别reloadData做到了这一点 - 表视图(的可见部分)的全面更新。

如果您只需要更新某些单元格,即更新,插入,移除或移动,请改为使用适当的更新方法。这甚至会动画变化。

1

据我所知,[self.tableView reloadData]更多用于如果您的数据已经完全改变了,你要显示的最新版本(或者过滤器发生了变化等)

即假设你有一张显示足球运动员的表格,并且您“轻击开关”以显示来自不同球队的足球运动员。在这种情况下,你会倾向于使用reloadData。这将会刷新整个表格。

[self.tableView beginUpdates]; 
[self.tableView insertRowsAtIndexPaths:insertIndexPathswithRowAnimation:UITableViewRowAnimationAutomatic]; 
[self.tableView endUpdates]; 

用于将新数据添加到显示的当前数据集中。这不会刷新整个,但会将新行动画到当前表格中。

1

如果你想重新加载一个部分或几行,也有这样做的方法。

对于行:

[self.tableView reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation]; 

对于部分:

[self.tableView reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation];