IOS - UITableView分批显示数据 实现点击加载更多
Phone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10条,table底部有一察看更多选项,点击察看更多查看解析的剩余数据。基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中. 比如:
数据源是个array:
NSMutableArray *items;
ViewController的这个方法返回数据条数: +1是为了显示"加载更多"的那个cell
|
1
2
3
4
5
|
- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section { int count = [items count]; return count + 1; } |
这个方法定制cell的显示, 尤其是"加载更多"的那个cell:
|
1
2
3
4
5
6
7
8
9
|
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath { if([indexPath row] == ([items count])) { //创建loadMoreCell return loadMoreCell; } //create your data cell return cell; } |
还要处理"加载更多"的那个cell的选择事件,触发一个方法来加载更多数据到列表
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath { if (indexPath.row == [items count]) { [loadMoreCell setDisplayText:@"loading more ..."]; [loadMoreCell setAnimating:YES]; [self performSelectorInBackgroundselector(loadMore) withObject:nil]; //[loadMoreCell setHighlighted:NO]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; return; } //其他cell的事件 } |
加载数据的方法:
|
1
2
3
4
5
6
|
-(void)loadMore { NSMutableArray *more; //加载你的数据 [self performSelectorOnMainThreadselector(appendTableWith withObject:more waitUntilDone:NO]; } |
添加数据到列表:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
-(void) appendTableWithNSMutableArray *)data { for (int i=0;i<[data count];i++) { [items addObject:[data objectAtIndex:i]]; } NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10]; for (int ind = 0; ind < [data count]; ind++) { NSIndexPath *newPath = [NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0]; [insertIndexPaths addObject:newPath]; } [self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade]; }
|
IOS - UITableView分批显示数据 实现点击加载更多的更多相关文章
- js点击加载更多可以增加几条数据的显示
<div class="list"> <div class="one"> <div class="img" ...
- ajax点击加载更多数据图片(预加载)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- PHP+Ajax点击加载更多列表数据实例
一款简单实用的PHP+Ajax点击加载更多列表数据实例,实现原理:通过“更多”按钮向服务端发送Ajax请求,PHP根据分页参数查询将最新的几条记录,数据以JSON形式返回,前台Query解析JSON数 ...
- Vue——轻松实现vue底部点击加载更多
前言 需求总是不断改变的,好吧,今天就把vue如何实现逐步加载更多和分布加载更多说下,默认你知道如何去请求数据的哈 一次请求 页面 使用slice来进行限制展现从0,a的数据 <div v-fo ...
- UITableview优化随笔(1)-提高加载更多内容时的效率
UITableView上拉加载更多的功能相信很多应用都会用到,类似朋友圈.微博这样的应用,tableView中的数据内容高度根据内容来变化,同时需要加载大量的数据(上拉加载更多),要怎样才能保证加载数 ...
- jQuery+php+Ajax文章列表点击加载更多功能
jQuery+php+Ajax实现的一个简单实用的文章列表点击加载更多功能,点击加载更多按钮,文章列表加载更多数据,加载中有loading动画效果. js部分: <script type=&qu ...
- Spring+Hibernate+struts2+JPA 注解+跨域//完成手机端点击加载更多 下拉加载更多
一.使用IDEA新建一个maven项目(student) 1.1.0编写pom文件,添加项目所需要的包 <?xml version="1.0" encoding=" ...
- vux loadmore + axios 实现点击加载更多
在微信项目中有应用过几个上拉加载更多的组件,但总会出现一些兼容性方面的bug,需要各种补漏(注:组件都是基于iscroll实现的, iscroll原本就有些坑).Vux也有提供Scroller组件实现 ...
- PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载
这个效果好,速度快,只能点击更多加载,不能滚动自动加载 一.HTML部分 <div id="more"> <div class="single_item ...
随机推荐
- 升级xcode7.0 第三方库不能用的解决方法(bitcode是什么鬼?)
升级完xcode,真机运行发现报错,第三方库错误,微信SDK,高德SDK都报错,如下: ‘/Users/**/Framework/SDKs/PolymerPay/Library/mobStat/lib ...
- hadoop安装实战(mac实操)
集群环境配置参考(http://blog.csdn.net/zcf1002797280/article/details/49500027) 参考:http://www.cnblogs.com/liul ...
- C#5.0 特性
Visual Studio 2012 中 Visual C# 的新增功能 Lambda表达式 表达式树:把代码,转换成数据,然后分析数据发现其组成部分,最后转换成可以传递到其他程序的字符串 LinQ表 ...
- nyoj 14 会场安排问题(贪心专题)java
会场安排问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...
- nyoj 252 01串 动态规划( java)
当n=2时, 输出 3:当n=3时, 输出 5:当n=4时, 输出 8: #### 分析: 当n=4时,如 0101 符合条件, 当第一个位置是0时,还剩3个位置 ,与n=3时个数相等: 符合条件的为 ...
- wordpress自动清理评论回收站
有时wordpress的垃圾评论实在让人心烦,杂草难除根,footprint吹又生.如果你有心情的话会一个个把垃圾评论放入回收站,但是时间一长,回收站里的东西越堆越多,你可以点击回收站,然后再点一下e ...
- springmvc之前后台传值
一.向后台传值 1.项目结构 2.jar包 3.spring-config.xml <?xml version="1.0" encoding="UTF-8" ...
- PHPCMS系统使用的弹出窗口插件artDialog
来源: http://aui.github.io/artDialog/doc/index.html (官方) http://lab.seaning.com/ http://www.mb5u.com/ ...
- 观察者(Observer)模式
http://www.cnblogs.com/zhenyulu/articles/73723.html 一. 观察者(Observer)模式 观察者模式又叫做发布-订阅(Publish/Subscri ...
- Linux之编译需要的文件变化时刻