我想完全重置 UITableView 的滚动位置,以便每次打开它时,它都会显示最上面的项目。换句话说,我想每次打开 TableView 时将其滚动到顶部。
我尝试使用以下代码,但看起来我误解了文档:
- (void)viewWillAppear:(BOOL)animated {
[tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:NO];
}
这是错误的方法吗?
最佳答案
8月份得到了UITableView特有的方法。另一种方法是:
[tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
该方法定义在UITableView的父类UIScrollView中。上面的示例告诉它滚动到 0,0 处的 1x1 框 - 换句话说,就是左上角。
关于iphone - 如何重置 UITableView 的滚动位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/307857/