如何在向下滚动时在UITableView中实现“加载”?
问题描述:
我正在开发iPhone应用程序。此应用程序包含大量的Web服务。我需要逐页显示UITableView中的列表。如何在向下滚动UITableview时显示“加载”并调用Web服务?请帮助我..如何在向下滚动时在UITableView中实现“加载”?
答
我假设您将自定义单元添加到表视图的底部以指示当前数据集的结尾。当您创建该单元格时,请将其tag
属性设置为您之前定义的有意义的常量,如END_OF_TABLE_CELL
。
然后使用委托方法tableView:willDisplayCell:forRowAtIndexPath
检查要显示的单元格是否是您的自定义单元格,并触发表格数据源的重新加载。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//check your cell's tag
if (cell.tag == END_OF_TABLE_CELL) {
//Call your custom method to fetch more data and reload the table
// You should also remove this custom cell from the table and add one at the bottom
}
}
这样,您将有自我刷新每当用户向下滚动到足以使自定义单元格进入视野的表。
祝你好运!
+0
我做了这个,它的工作就像一个魅力。这种方法的更深入的教程:http://nsscreencast.com/episodes/8-automatic-uitableview-paging。 – niaher
感谢您删除感叹号! – Maarten