iPhone tableview分批显示数据
来源:互联网 发布:java怎么学 编辑:程序博客网 时间:2024/05/18 11:25
数据源是个array:
NSMutableArray *items;
ViewController的这个方法返回数据条数: +1是为了显示"加载更多"的那个cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = [items count];
return count + 1;
}
这个方法定制cell的显示, 尤其是"加载更多"的那个cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath row] == ([items count])) {
//创建loadMoreCell
return loadMoreCell;
}
//create your data cell
return cell;
}
还要处理"加载更多"的那个cell的选择事件,触发一个方法来加载更多数据到列表
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [items count]) {
[loadMoreCell setDisplayText:@"loading more ..."];
[loadMoreCell setAnimating:YES];
[self performSelectorInBackground:@selector(loadMore) withObject:nil];
//[loadMoreCell setHighlighted:NO];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
return;
}
//其他cell的事件
}
加载数据的方法:
-(void)loadMore
{
NSMutableArray *more;
//加载你的数据
[self performSelectorOnMainThread:@selector(appendTableWith:) withObject:more waitUntilDone:NO];
}
添加数据到列表:
-(void) appendTableWith:(NSMutableArray *)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];
}
- iPhone tableview分批显示数据
- 转载:iPhone tableview分批显示数据
- tableview分批显示数据
- 详解iPhone Tableview分批显示数据 实现点击加载更多
- 【學習筆記】tableview分批显示数据
- 数据分批显示
- 数据分批显示
- cocoa UITableView数据分批显示
- 119.ListView数据的分批显示
- IOS tableView数据显示
- SWT 中TableView显示数据
- 数据库分页\分批显示
- 经纬度分批显示
- [iphone]tableview
- 分批读取Oracle数据
- 数据的分批加载
- 集合数据分批处理
- ListView分批加载数据
- LDA主题模型简介
- Java语言实现的各种排序源代码--希尔排序
- 配置 Linux Iptable
- HeapSort.cpp
- 写了一个简单实用的PHP模板引擎
- iPhone tableview分批显示数据
- InsertSortTesting1004.cpp
- MergeSortTesting1004.cpp
- eclipse创建user library
- StackWithMinTesting1007.cpp
- NSInvocation简单使用
- 如何使用免费敏捷工具放飞你的创造力?
- 最老程序员创业札记:全文检索、数据挖掘、推荐引擎应用27
- 策略模式testing1002.cpp