gpt4 book ai didi

iphone - UITableView滚动到特定位置

转载 作者:行者123 更新时间:2023-12-03 18:33:23 24 4
gpt4 key购买 nike

我正在使用 iPhone SDK 3.1.3。我有一个 UITableViewController 从另一个 Controller 获取数据。 TableView 作为 subview 添加到主视图中,但框架被设置为不可见。表格 View 框架已更新,并可通过点击按钮在主视图上滑动。

表格 View 出现,我滚动到最后一行。如果我选择最后一行,我会用更多数据重新加载表。该表会更新更多数据。除了滚动位置始终位于顶部之外,一切正常。

我需要滚动位置是我单击以加载更多数据的最后一行。我保存滚动位置并在加载更多数据后调用以下代码。它执行时没有问题,但滚动位置始终位于顶部。

 [theTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:savedScrollPosition inSection:0] atScrollPosition:savedScrollPosition animated:NO];

上面的好像没有什么作用。 ViewWillAppear: ViewDidAppear: 不会触发,我被告知如果 View Controller 在代码中实例化(这种情况),它们就不会触发。请帮助我弄清楚在重新加载表格后如何以及何时设置滚动位置 ([theTableView reloadData]),以便它位于我单击的行。

重新加载表格 View 和滚动的代码

 ////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];
}

最佳答案

这似乎成功了。

[theTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:savedScrollPosition inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
CGPoint point = theTableView.contentOffset;
point .y -= theTableView.rowHeight;
theTableView.contentOffset = point;

关于iphone - UITableView滚动到特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2685548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com