将数据添加到数据源数组或者字典中,数据添加之后就会通知表格视图,因为TableView和它的数据源必须一直是同步的,通常可以使用
[self.tableView reloadData];来更新数据。
但是也可以重新创建一个单元格,将单元格插入到表中:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[self.players count]-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
这种方法添加的单元格可以设置动画,好看一些。
本文介绍了如何在UITableView中更新数据的方法,包括使用reloadData整体刷新表格视图,以及通过insertRowsAtIndexPaths插入新行并可设置动画的方式。后者能够提供更佳的用户体验。
1269

被折叠的 条评论
为什么被折叠?



