iOS 刷新单个Cell

在开发过程中,经常遇到tableView数据刷新的情况,,只用更新一行Cell数据时,用[tableview reloadData]来刷新,这样不仅浪费内存,而且有时候还很难达到预期,本文介绍如何刷新固定的某一行的Cell;
如何获取需要刷新Cell的IndexPath信息,请移步链接:http://www.jianshu.com/p/e872225fa860
自定义NSIndexPath的值,代码如下:

//section = 0 ,row = 2;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];

调用代码:

//刷新单个cell
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
//刷新单个section
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:indexPath.section];  
[tableview reloadSections:indexSet withRowAnimation: UITableViewRowAnimationNone]; 

另提一句,使用上述单个刷新方法的话,就不要在自定义cell类中重写- (void)setFrame:(CGRect)frame;方法了,否则会调用两次出问题;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容