转:详解iPhone Tableview分批显示数据 点击加载更多
2013-05-27 13:34
756 查看
iPhone Tableview分批显示数据是本文要介绍的内容,主要讲解的是数据的显示。iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10条,table底部有一察看更多选项,点击察看更多查看解析的剩余数据。基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中. 比如: 数据源是个array: 1. NSMutableArray *items; ViewController的这个方法返回数据条数: +1是为了显示"加载更多"的那个cell 1. - (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section { 2. int count = [items count]; 3. return count + 1; 4. } 这个方法定制cell的显示, 尤其是"加载更多"的那个cell: 1. - (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath { 2. if([indexPath row] == ([items count])) { 3. //创建loadMoreCell 4. return loadMoreCell; 5. } 6. //create your data cell 7. return cell; 8. } 还要处理"加载更多"的那个cell的选择事件,触发一个方法来加载更多数据到列表 1. - (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath { 2. 3. if (indexPath.row == [items count]) { 4. [loadMoreCell setDisplayText"loading more ..."]; 5. [loadMoreCell setAnimating:YES]; 6. [self performSelectorInBackgroundselector(loadMore) withObject:nil]; 7. //[loadMoreCell setHighlighted:NO]; 8. [tableView deselectRowAtIndexPath:indexPath animated:YES]; 9. return; 10. } 11. //其他cell的事件 12. } 加载数据的方法: 1. -(void)loadMore 2. { 3. NSMutableArray *more; 4. //加载你的数据 5. [self performSelectorOnMainThreadselector(appendTableWith withObject:more waitUntilDone:NO]; 6. } 添加数据到列表: 1. -(void) appendTableWithNSMutableArray *)data 2. { 3. for (int i=0;i<[data count];i++) { 4. [items addObject:[data objectAtIndex:i]]; 5. } 6. NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10]; 7. for (int ind = 0; ind < [data count]; ind++) { 8.
参考:http://blog.163.com/cai_1111/blog/static/198815027201110905933871/
http://www.oschina.net/question/916968_88945
Debug:
1、再使用点击加载更多时,一定要注意,UITableView 要在viewDidLoad方法中初始化,否则每点一次“点击加载更多”tableview就初始化一次。数据没法从你点击的位置开始显示。
相关文章推荐
- 详解iPhone Tableview分批显示数据
- 点击加载更多(适用于listview在scrollview单行显示修正后多数据加载慢的情况)
- 详解iPhone Tableview分批显示数据 实现点击加载更多
- thinkphp使用js实现点击加载更多后, 底部无刷新加载出新的数据并显示在该页
- 实现解析数据table表最后的点击显示更多数据的代码
- jsp加载时想直接让jsp页面直接显示已处理过得数据(此页面是点击链接进入)即请求servlet
- 使用jquery.more.js来实现点击底部更多后, 底部加载出新的数据
- ExpandableList默认显示三条数据,点击更多显示全部(带上拉下拉)
- iOS:详解MJRefresh刷新加载更多数据的第三方库
- jQuery 中的 Ajax 全局事件 当用户点击页面上某一按钮请求数据时,在页面上显示 loading... ,页面加载完成后隐藏
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- ListView显示数据库的数据-采用自定义布局-向上滑动可以加载更多数据
- SwipeRefreshLayout配合RecyclerView实现下拉刷新和上拉加载更多以及没有数据的显示
- 使用jquery.more.js来实现点击底部更多后, 底部加载出新的数据
- ListView无数据,显示点击加载等友好界面
- UITableView 分页显示、加载更多,数据源远程数据,解析JSON,以及iOS☞Category
- SwipeRefreshLayout配合RecyclerView实现下拉刷新和上拉加载更多以及没有数据的显示
- java +jsp实现的点击加载更多,实现数据的异步加载
- Android下拉刷新库,利用viewdraghelper实现,集成了下拉刷新,底部加载更多,数据初始加载显示loading等功能
- iOS:详解MJRefresh刷新加载更多数据的第三方库