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 ...
随机推荐
- ELK日志分析系统搭建(转)
摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticSearch,一款基于Apache Lucene的开源分布式搜索引擎)中便于查找和分析,在研究 ...
- putchar和puts
#include<stdio.h> int main() { char a = 'h'; char b[] = "hello"; putchar(a); //putch ...
- 必须知道的.net——学习笔记1
1.对象的生成(出生) Person aperson=new Person("小张",25) 构造过程:分配存储空间—初始化附加成员—调用构造函数 2.对象的旅程(在一定的约定与规 ...
- pipe-filter 真难找啊
http://blog.csdn.net/absurd/article/details/4307903
- POJ 2115 C Looooops
扩展GCD...一定要(1L<<k),不然k=31是会出错的 .... C Looooops Time Limit: 1000MS Mem ...
- button 按钮
<!DOCTYPE html> <html> <body> <h1>我的第一段 JavaScript</h1> <p> Java ...
- Bootstrap编码规范
黄金定律 永远遵循同一套编码规范 -- 可以是这里列出的,也可以是你自己总结的.如果你发现本规范中有任何错误,敬请指正.通过 open an issue on GitHub为本规范添加或贡献内容. 不 ...
- Flash相册-------3D旋转应用
1.图层一,图片1,转换为元件 2.3D旋转工具,变形--->y->180
- windows server 2008 R2 SP1 安装exchange 2010
一. 先决条件 若在windows server R2 SP1企业版系统上典型安装exchange server2010 SP3,则需要提前确定一下先决条件 AD域环境,域和林的功能级别必须是wind ...
- Linux资源站
1.<鸟哥的linux私房菜>中提供的台湾高速网络中心ftp站:http://ftp.twaren.net/Linux/CentOS/5/