IOS问题在特定点获取索引路径行

Sco*_*Bot 6 iphone uitableview ios

我有一个视图控制器,其中包含导航栏,表格视图和工具栏.我在视图控制器中包含了UITableViewDelegate,并通过故事板正确地分配了表的数据源并委托给视图控制器.表格视图从远程数据库加载其数据,一旦表格滚动到最后一个单元格,更多数据将加载到表格中.我通过使用scrollViewDidScroll和indexPathForRowAtPoint方法实现了这一点,如下文所述:如何知道UITableView何时在iPhone中滚动到底部.但是,当我运行应用程序并滚动表时,indexPathForRowAtPoint返回的唯一索引路径是表加载时指定点的路径.这是我滚动时得到的代码和输出:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint bottomPoint = CGPointMake(160, 430);
    CGPoint topPoint = CGPointMake(160, 10);

    NSLog(@"%d", [[_tableView indexPathForRowAtPoint:bottomPoint] row]);

}
Run Code Online (Sandbox Code Playgroud)

每次我滚动以下输出:

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
Run Code Online (Sandbox Code Playgroud)

其中3是单元格的indexPath.row,当控制器加载时,底点开启.我做错了什么,为什么会这样?是否与UITableView位于父视图控制器内的事实有关?

Hal*_*alR 9

bottomPoint正在寻找你的位置scrollView.你scrollView包含一张表,所有的单元格都在相同的位置,相对于你的scrollView.这就是为什么你总是在那时得到相同的单元格.

滚动时,细胞不中招scrollView,在scrollView"动作"相对于其父.这是通过更改其contentOffset来完成的.

如果您将scrollView'sy content content offset 添加到您的内容中bottomPoint,您将获得您可能正在寻找的内容scrollView.

像这样:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint bottomPoint = CGPointMake(160, 430) - scrollView.contentOffset.y;
    CGPoint topPoint = CGPointMake(160, 10);

    NSLog(@"%d", [[_tableView indexPathForRowAtPoint:bottomPoint] row]);

}
Run Code Online (Sandbox Code Playgroud)