views:

551

answers:

1

I have two tabs in my app, each of them is a UITableView, and each of the views in the two tabs has its own DetailViewController. Now, if I click on a TableViewCell in the DetailViewController in the first tab, I want to jump to the DetailViewController of the second tab. I know how to access the second tab

    self.tabBarController.selectedIndex = 1;

and I know how to access the DetailViewController, but only without jumping to the second tab.

Is it possible to access the second tab, and then access its DetailViewController? It would be best if the main TableView in the second tab wouldn't be visible at all, so, it should jump directly to the DetailViewController of the second tab, with the navigation controller showing the "back" button to the main view controller and the second tab highlighted. Is this possible? And, if it is, how can I do this?

Thanks in advance :-)

+1  A: 

The tabBarController has an array with the viewController of every tab. You can push the DetailViewController like this:

[[self.tabBarController.viewControllers objectAtIndex:1] pushViewController:detailViewController animated:NO];

Before that you might want to pop to the rootViewController:

[[self.tabBarController.viewControllers objectAtIndex:1] popToRootViewControllerAnimated:NO];
Florian