iphone - 点击状态栏时将所有 ScrollView 滚动到顶部

标签 iphone objective-c uitableview uiscrollview

我的 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/

相关文章:

objective-c - iOS 6 上的 XMPP 类中的警告

ios - 未设置 AVAssetResourceLoader 委托(delegate)

iPhone : OpenGL ES : Detecting if you have tapped a object (cube) on screen

ios - 如何在 xamarin.ios 应用程序内显示来自远程 url 的文件

ios - View 之间的索引值传递

ios - 如何获取所选sectionIndexTitle的点(CGPoint)

ios - 创建一个显示 UIAlertView 的实用程序类

swift - 上一个 View Controller 中的更新按钮

iphone - 到达特定位置时如何在表格 View 中选择一行?

ios - 在长时间计算期间保持 UITableView 平滑滚动