數(shù)據(jù)刷新
- 重新刷新屏幕上的所有 cell
[self.tableView reloadData];
- 插入指定行數(shù)的 cell
[self.tableView insertRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]]
withRowAnimation:UITableViewRowAnimationFade];
- 更新指定行數(shù)據(jù)
[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];
區(qū)別:reloadData 方法通用诫尽;其它三個(gè)方法使用有注意點(diǎn):數(shù)據(jù)增刪改的數(shù)目必須和方法中的要修改的數(shù)據(jù)數(shù)量一樣多莱睁。
數(shù)據(jù)刷新的原則
- 通過(guò)修改模型數(shù)據(jù)柒室,來(lái)修改 tableView 的展示
- 先修改模型數(shù)據(jù)
- 再調(diào)用數(shù)據(jù)刷新方法
- 不要直接修改 cell 上面子控件的屬性