iOS开发小技巧:刷新UITableView
来源:互联网 发布:广州淘宝模特 编辑:程序博客网 时间:2024/05/29 09:02
在很多APP界面都用到的UITableView,对iOS开发者来说一定不陌生吧。网上关于UITableView的文章早已多不胜数,尤其是关于UITableView优化方面的,对开发者来说非常值得一看。
现在就来看看,刷新UITableView该怎么做吧,一般情况下,我们会通过直接调用reloadData的方法,去刷新UITableView的。
刷新UITableView
[self.tableView reloadData];
reloadData是刷新整个UITableView,有时候,我们可能需要局部刷新。比如:只刷新一个cell、只刷新一个section等等。这个时候在调用reloadData方法,虽然用户看不出来,但是有些浪费资源。
刷新局部cell
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableViewreloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil]
withRowAnimation:UITableViewRowAnimationFade];
这是刷新第一个section的第一个cell很方便的一种方法,虽然看上去,代码变多了,但是很节省资源,尽量减少刷新频率,这也是在iOS开发中对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
};
以上便是在iOS开发中,刷新UITableView的几个小技巧。
现在就来看看,刷新UITableView该怎么做吧,一般情况下,我们会通过直接调用reloadData的方法,去刷新UITableView的。
刷新UITableView
[self.tableView reloadData];
reloadData是刷新整个UITableView,有时候,我们可能需要局部刷新。比如:只刷新一个cell、只刷新一个section等等。这个时候在调用reloadData方法,虽然用户看不出来,但是有些浪费资源。
刷新局部cell
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableViewreloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil]
withRowAnimation:UITableViewRowAnimationFade];
这是刷新第一个section的第一个cell很方便的一种方法,虽然看上去,代码变多了,但是很节省资源,尽量减少刷新频率,这也是在iOS开发中对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
};
以上便是在iOS开发中,刷新UITableView的几个小技巧。
0 0
- iOS开发小技巧:刷新UITableView
- iOS开发小技巧:刷新UITableView
- iOS开发小技巧:刷新UITableView
- iOS开发小技巧:刷新UITableView
- UITableView刷新小技巧
- iOS - UITableView中 Header上小技巧:
- 【iOS开发】UITableView的局部刷新与全局刷新
- iOS开发 小技巧
- iOS 开发小技巧
- ios开发小技巧
- ios开发小技巧
- iOS 开发小技巧
- IOS 开发小技巧
- iOS开发小技巧
- ios开发小技巧
- iOS开发小技巧
- iOS 开发小技巧
- iOS 开发小技巧
- SQL向下递归&向上递归 (无限级父子查询)
- php面试题(三)
- 配置JDK环境变量
- 昂贵的聘礼(迪杰特斯拉最短路径)
- centos系统中挂载盘和扩容硬盘的方法
- iOS开发小技巧:刷新UITableView
- 解密加密的URL图片数据
- 关于HTML5中meta name="viewport" 的用法
- codevs1058合唱队形
- cpp的stl的位标识
- 用Python学习数据结构1--队列
- HTML5基础(一)
- 《breaking bad》第二次观影感受
- Eclipse中通过Tomcat运行JavaWeb项目发生内存溢出:java.lang.OutOfMemoryError: PermGen space 错误的解决方案