博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
刷新UITableView
阅读量:6983 次
发布时间:2019-06-27

本文共 1586 字,大约阅读时间需要 5 分钟。

【from】http://www.superqq.com/blog/2015/08/18/ios-development-refresh-uitableview/

UITableView对于iOS开发者来说一定不会陌生,很有可能你的APP很多界面都用到它。关于UITableView的文章,想必已经不计其数,没事可以多看看。特别是UITableView优化的文章,非常值得仔细琢磨一番。

今天我们来看看如何刷新UITableView的,一般情况下,刷新UITableView,我们会直接调用reloadData方法。

刷新UITableView

[self.tableView reloadData];

reloadData是刷新整个UITableView,有时候,我们可能需要局部刷新。比如:只刷新一个cell、只刷新一个section等等。这个时候在调用reloadData方法,虽然用户看不出来,但是有些浪费资源。

刷新局部cell

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];

这样就可以很方便的刷新第一个section的第一个cell。虽然看起来代码多了,但是确实比较节省资源。尽量少的刷新,也是UITableView的一种优化。

局部刷新section

NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:0];[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];

上面这段代码是刷新第0个section。

刷新动画

刷新UITableView还有几个动画:

typedef NS_ENUM(NSInteger, UITableViewRowAnimation) {    UITableViewRowAnimationFade,   //淡入淡出    UITableViewRowAnimationRight,  //从右滑入         // slide in from right (or out to right)    UITableViewRowAnimationLeft,   //从左滑入    UITableViewRowAnimationTop,     //从上滑入    UITableViewRowAnimationBottom,  //从下滑入    UITableViewRowAnimationNone,            // available in iOS 3.0    UITableViewRowAnimationMiddle,          // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy    UITableViewRowAnimationAutomatic = 100  // available in iOS 5.0.  chooses an appropriate animation style for you};

 

 

转载于:https://www.cnblogs.com/lucky-star-star/p/5721927.html

你可能感兴趣的文章
使用graphite和grafana进行应用程序监控
查看>>
github推送错误:已经有此代码,不允许覆盖的解决方法
查看>>
C#MysqlHelper
查看>>
SpringMVC Hello World 实例
查看>>
MySQL BETWEEN 用法
查看>>
vim开启自动缩进
查看>>
【转】js之iframe子页面与父页面通信
查看>>
java设计模式_模版模式
查看>>
摄像机平滑更随脚本
查看>>
Struts2 标签配置详细
查看>>
需求管理工具比较 Doors_Requistie Pro_RDM
查看>>
centos+php+nginx的php.ini无法加载的问题
查看>>
从菜鸟到专家的五步编程语言学习法
查看>>
RequestQueue
查看>>
Android TextView 属性设置
查看>>
html元素分类以及嵌套规则
查看>>
android dpi
查看>>
C语言的预处理、编译、汇编、链接
查看>>
nginx的启动、停止、平滑重启
查看>>
(转)ASIHTTPRequest 详解, http 请求终结者
查看>>