作者:rsidugjig | 来源:互联网 | 2023-01-13 21:17
我有一个表视图,我希望它在第一次出现时始终滚动到顶部.以下代码用于工作正常但在iOS 11中不再执行任何操作.如何在iOS 11中滚动到表格视图的顶部?
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
}
Jack..
14
您可以使用 scrollToRowAtIndexPath
方法 -
ObjC
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:true];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:true];
}
SWIFT 4
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: true)
}
您还可以通过设置indexpath
各种行和节值来设置自定义行.
1> Jack..:
您可以使用 scrollToRowAtIndexPath
方法 -
ObjC
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:true];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:true];
}
SWIFT 4
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: true)
}
您还可以通过设置indexpath
各种行和节值来设置自定义行.