UITableView中的tableFooterView实现新浪微博下拉无限添加

woskxmcnvb 2011-03-08 04:18:27
没有人用过tableFooterView吗?或者这样的功能(tableView移动到最后一行会添加刷新数据,就是新浪微博那个效果)有没有其他方法可以实现?求高手!!
...全文
1691 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
一丝晨光 2012-01-12
  • 打赏
  • 举报
回复
就是把最后一行写成"更多"
吹牛啤 2011-09-18
  • 打赏
  • 举报
回复
mark 一下
Mark_xy 2011-07-09
  • 打赏
  • 举报
回复
用UITableViewDelegate中的这个方法:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

判定tableView中的数组数是否即将显示最后一个cell,if (indexPath.row == [self.dataArr count]-1)

如果是的话,self.tableView.tableFooterView = footSpinnerView;//footSpinnerView为自定义的UIView,上面加了一个旋转的UIActivityIndicatorView即可,记得让UIActivityIndicatorView startAnimation

加上你关于刷新数组的逻辑,如从数据库中取出更多的数据,取完数据后,将self.tableView.tableFooterView设nil即可。


Demo:

#pragma mark -
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [self.productArr count]-1) {

[self setupFootSpinnerView];

self.tableView.tableFooterView = footSpinnerView;

if (currentArrCount < dataCount) {
currentArrCount += 5;

self.dataArr = [dao getArrayOfDataLimit:currentArrCount offset:0];//从数据库中重新取数据
[self.tableView reloadData];

}else{
self.tableView.tableFooterView = nil;

}


}

}
Proteas 2011-03-08
  • 打赏
  • 举报
回复
这个是这样实现的:
首先,UITableView 的父视图是 UIScrollView。
然后,在 FooterView 中添加一个 UIView,
并记住 offset(在 UIScrollView 中的),
当滑动点超过这个 offset 时,
去服务器取数据,
添加到数据源中。

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧