Switch to the UITableView controller and scroll to the beginning of the section
Good morning,
I hope someone can shed some light on how I can switch from a ViewController nested within a tab bar controller to another ViewController nested within a navigation controller nested within a tab bar controller and then scrolling through the table view in the section navigation manager to a specific section.
I found at least that I need to toggle the tab bar controllers with
[self.applicationTabBarController setSelectedIndex:1];
and I can get a link to the second view controller with
UINavigationController *secondTabNavController = (UINavigationController *)[[self.applicationTabBarController viewControllers] objectAtIndex:1];
MyViewController *myViewController = (MyViewController *)[[ordersNav viewControllers] objectAtIndex:0];
But I don't understand how I can scroll the UITableView to a 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 downloaded and has section 3.
Finally, my first view controller calls the above code, which is in the application delegate.
Thank.
source to share
You need to be careful if you place this call scrollToRowAtIndexPath
. If you put it before loading the view, it can run this method on nil. I would say there is a function in myViewController
called scrollToRowAtIndexPath:
that determines if the view is currently being displayed, and if it is, it just calls the tableView version. If not, keep indexPath until called viewWillAppear:
and run it.
source to share