您的位置:首页 > 其它

tableView - 数据刷新

2015-06-19 01:14 344 查看

tableView数据刷新方法

重新刷新屏幕上的所有cell

没有动画效果

[self.tableView reloadData];


刷新特定行的cell

有动画效果

[self.tableView reloadRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
]
withRowAnimation:UITableViewRowAnimationLeft];


插入特定行数的cell

有动画效果

[self.tableView insertRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
]
withRowAnimation:UITableViewRowAnimationLeft];


删除特定行数的cell

有动画效果

[self.tableView deleteRowsAtIndexPaths:@[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
]
withRowAnimation:UITableViewRowAnimationLeft];


数据刷新的原则

通过修改模型数据,来修改tableView的展示

先修改模型数据

再调用数据刷新方法

不要直接修改cell上面子控件的属性

如果不要求动画效果,一般使用reloadData刷新数据

// 刷新,删除和刷新特定行要求,删除的和刷新的行数必须要相等
//- reloadRowsAtIndexPaths
//- insertRowsAtIndexPaths
//- insertRowsAtIndexPaths

// 移除最前面两行(注意下标)
[self.dealsData removeObjectAtIndex:0];
[self.dealsData removeObjectAtIndex:0];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: