切换到 UITableView 控制器并滚动到部分的开头
早上好,
我希望有人能够阐明如何从嵌套在选项卡栏控制器中的 ViewController 切换到嵌套在嵌套在选项卡栏控制器中的导航控制器中的另一个 ViewController,然后滚动表格视图在部分导航控制器中到特定部分。
我至少找到了切换选项卡栏控制器所需的内容
[self.applicationTabBarController setSelectedIndex:1];
,并且能够获得对第二个视图控制器的引用,
UINavigationController *secondTabNavController = (UINavigationController *)[[self.applicationTabBarController viewControllers] objectAtIndex:1];
MyViewController *myViewController = (MyViewController *)[[ordersNav viewControllers] objectAtIndex:0];
但我不清楚的是如何将 UITableView 滚动到特定部分。 我尝试
NSIndexPath *myPath = [NSIndexPath indexPathForRow:0 inSection:3];
[myViewController.ordersTableView scrollToRowAtIndexPath:myPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
当然,
假设第二个视图已加载,并且有第 3 部分。最后,我的第一个视图控制器调用驻留在应用程序委托中的上述代码。
谢谢。
Good Morning,
I'm hoping someone would be able to shed some light on how i can switch from a ViewController nested in a tab bar controller to another ViewController nested in a navigation controller nested in the tab bar controller, and then scroll the table view in the section navigation controller to a specific section.
I have found at least what i need to switch the tab bar controllers with
[self.applicationTabBarController setSelectedIndex:1];
and i am able to get a reference to the second view controller with
UINavigationController *secondTabNavController = (UINavigationController *)[[self.applicationTabBarController viewControllers] objectAtIndex:1];
MyViewController *myViewController = (MyViewController *)[[ordersNav viewControllers] objectAtIndex:0];
But what i am unclear about is how i can scroll the UITableView to the specific section. I tried
NSIndexPath *myPath = [NSIndexPath indexPathForRow:0 inSection:3];
[myViewController.ordersTableView scrollToRowAtIndexPath:myPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
Assuming of course, that the second view has been loaded, and has a section 3.
And lastly, my first view controller calls the above code that resides in the app delegate.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要小心放置
scrollToRowAtIndexPath
调用的位置。如果你把它放在视图加载之前,它可能会在 nil 上运行该方法。我想说的是myViewController
中有一个名为scrollToRowAtIndexPath:
的函数,它确定视图当前是否显示,如果是,则只调用 tableView 版本。如果没有,请保存indexPath,直到调用viewWillAppear:
并运行它。You need to be careful where you put that
scrollToRowAtIndexPath
call. If you put it before the view loads, it may be running that method on nil. I would say have a function inmyViewController
calledscrollToRowAtIndexPath:
which determines if the view is currently displayed, and if it is, just calls the tableView version. If not, save the indexPath untilviewWillAppear:
is called and run it then.