我正在使用iPhone SDK 3.1.3。我有一个UITableViewController
从其他控制器获取数据。表格视图作为子视图添加到主视图中,但框架已设置为不可见。通过点击按钮,表格视图框架被更新并且在主视图上滑动。UITableView滚动到特定位置
表格视图出现,我滚动到最后一行。如果我选择最后一行,我会用更多的数据重新加载表格。该表获得更多数据更新。一切工作正常,除了滚动位置始终是顶部。
我需要滚动位置是我点击加载更多数据的最后一行。我保存滚动位置并在加载更多数据后调用下面的代码。它执行没有问题,但滚动位置始终是最高的。
[theTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:savedScrollPosition inSection:0] atScrollPosition:savedScrollPosition animated:NO];
上述似乎没有效果。 ViewWillAppear:
ViewDidAppear:
不会触发,我被告知如果视图控制器在代码中被实例化,情况就是这样,它们不会触发。请重新加载表格([theTableView reloadData]
)后,请帮助我确定如何以及何时设置滚动位置,以便它位于我点击的行上。
代码重新加载表视图&滚动
////performAction will notify the tableviewcontroller which will result in didPerformAction being called
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == lastRow)
{
savedScrollPosition = lastRow;
//perform the action
[controller performAction];
}
}
- (void) didPerformAction:(NSNotification *)obj
{
[theTableView reloadData];
[theTableView
scrollToRowAtIndexPath: [NSIndexPath indexPathForRow:savedScrollPosition inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:NO];
}
这个语句中的savedScrollPosition是什么 – 2015-07-10 08:31:14