数据刷新
- 重新刷新屏幕上的所有 cell
[self.tableView reloadData];
- 插入指定行数的 cell
[self.tableView insertRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]]
withRowAnimation:UITableViewRowAnimationFade];
- 更新指定行数据
[self.tableView reloadRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:2 inSection:0]]
withRowAnimation:UITableViewRowAnimationNone];
- 删除指定行的 cell
[self.tableView deleteRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]]
withRowAnimation:UITableViewRowAnimationMiddle];
区别:reloadData 方法通用;其它三个方法使用有注意点:数据增删改的数目必须和方法中的要修改的数据数量一样多。
数据刷新的原则
- 通过修改模型数据,来修改 tableView 的展示
- 先修改模型数据
- 再调用数据刷新方法
- 不要直接修改 cell 上面子控件的属性
网友评论