【发布时间】:2013-06-04 11:28:03
【问题描述】:
我有一个包含导航栏、表格视图和工具栏的视图控制器。我将 UITableViewDelegate 包含在视图控制器中,并通过情节提要正确地将表的数据源和委托分配给视图控制器。表格视图从远程数据库加载其数据,一旦表格滚动到最后一个单元格,就会将更多数据加载到表格中。我通过使用以下帖子中概述的 scrollViewDidScroll 和 indexPathForRowAtPoint 方法实现了这一点:How to know when UITableView did scroll to bottom in iPhone。但是,当我运行应用程序并滚动表时,indexPathForRowAtPoint 返回的唯一索引路径是表加载时位于指定点的索引路径。这是我滚动时得到的代码和输出:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint bottomPoint = CGPointMake(160, 430);
CGPoint topPoint = CGPointMake(160, 10);
NSLog(@"%d", [[_tableView indexPathForRowAtPoint:bottomPoint] row]);
}
每次滚动都会输出以下内容:
2013-06-08 00:56:45.006 Coffee[24493:907] 3
2013-06-08 00:56:45.012 Coffee[24493:907] 3
2013-06-08 00:56:45.040 Coffee[24493:907] 3
2013-06-08 00:56:45.069 Coffee[24493:907] 3
2013-06-08 00:56:45.088 Coffee[24493:907] 3
2013-06-08 00:56:45.105 Coffee[24493:907] 3
2013-06-08 00:56:45.135 Coffee[24493:907] 3
2013-06-08 00:56:45.144 Coffee[24493:907] 3
2013-06-08 00:56:45.173 Coffee[24493:907] 3
2013-06-08 00:56:45.180 Coffee[24493:907] 3
其中 3 是控制器加载时底部点所在单元格的 indexPath.row。我做错了什么,为什么会这样?这与 UITableView 位于父视图控制器内的事实有什么关系吗?
【问题讨论】:
标签: iphone ios uitableview