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 ...
随机推荐
- springMVC之配置
1.项目结构 2.所需jar包 3.web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web ...
- Lua模块测试
Lua模块 ---------------------------------------------------------- ----------------------- 模块测试module_ ...
- 【Android面试】Android面试题集锦 (陆续更新)(最新2012-6-18) eoe上看到的
===============eoeAndroid社区推荐:======================= 1.Android开发新浪面试题[开发者必看哦]下载地址 http://www.eoeand ...
- ES6中Arguments和Parameters用法解析
原文链接 译文 ECMAScript 6 (也称 ECMAScript 2015) 是ECMAScript 标准的最新版本,显著地完善了JS中参数的处理方式.除了其它新特性外,我们还可以使用rest参 ...
- 关闭MyEclipse Derby服务
MyEclipse的Servers视图出现 MyEclipse Derby服务,一直想把它去掉在网上搜索了下,现已解决. 如下,MyEclipse菜单:window-->Preferences- ...
- STM32F103ZET6 用定时器级联方式输出特定数目的PWM(转载)
STM32F103ZET6里共有8个定时器,其中高级定时器有TIM1-TIM5.TIM8,共6个.这里需要使用定时器的级联功能,ST的RM0008 REV12的P388和P399页上有说明对于特定的定 ...
- 7.在AngularJS视图中实现指令
指令扩展了HTML的行为.可以创建自定义的HTML元素,属性和特定于应用程序的类与功能. 1.了解指令 指令是AngularJS模板标记和用于支持的JavaScript代码的组合.AngularJS指 ...
- atom 折腾记(转载的)
http://www.bkjia.com/webzh/999078.html
- spring boot redis缓存JedisPool使用
spring boot redis缓存JedisPool使用 添加依赖pom.xml中添加如下依赖 <!-- Spring Boot Redis --> <dependency> ...
- ios 关于使用异步网络请求时block回调的内存注意
在一个controller中,使用 NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest ...