我的 View 中有 3 个表格 View ,我想同时为所有表格启用滚动到顶部功能,即,如果用户点击状态栏,所有三个表格都应滚动到顶部位置。
我已经尝试使用我所有 tableView 的 scrollsToTop 属性,以及此属性的 YES/No 的各种组合。例如
table1.scrollsToTop = YES;
table2.scrollsToTop = NO;
table3.scrollsToTop = NO;
但无法实现这一点。我们是否有任何方法来获得点击状态栏的事件,以便我可以尝试将所有表格的内容偏移设置为顶部位置或任何其他解决方法。
如有任何帮助,我们将不胜感激。
最佳答案
通过重写 scrollViewShouldScrollToTop 方法解决了这个问题,如下所示,-
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
[table1 scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
[table2 scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
[table3 scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
return NO;
}
关于iphone - 点击状态栏时将所有 ScrollView 滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12858712/