如何在向下滚动时在UITableView中实现“加载”?

时间:2013-05-28 09:47:59

标签: iphone ios uitableview

我正在开发iPhone应用程序。此应用程序包含大量的Web服务。我需要逐页显示UITableView中的列表。如何在向下滚动UITableview时显示“正在加载”并调用Web服务?请帮帮我..

1 个答案:

答案 0 :(得分:1)

我假设您要在表视图的底部添加一个自定义单元格以指示当前数据集的结尾。创建该单元格时,请将其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
 }
}

通过这种方式,只要用户向下滚动足够远以使自定义单元格进入视图,您就会有一个自动刷新的表。

祝你好运!

相关问题