Reputation: 1627
I've got an app with a UITabBarController
that controls several UIViewControllers
. Within that controller there is a UITableViewController
. I'm trying to figure out how I can select a row on my tableview and push the view controller of one of my other tabs while actually navigating to that tab.
I've used performSegueWithIdentifier
: but it pushes the new view onto the same tab that my tableview is in. I'd like to navigate to the tab that the view I'm pushing to is on.
In case I haven't been clear: My tableview is in Tab 1. I click on a row. I want to get to Tab 2. So far I've been able to push the view controller for Tab 2 onto Tab 1. No Good.
Can anyone shed some light?
Thanks
Upvotes: 0
Views: 1015
Reputation: 77646
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *tab2ViewController = [self.tabBarController.viewControllers objectAtIndex:1];
NewViewControllerToPush *mvc = [[NewViewControllerToPush alloc] init];
[tab2ViewController.navigationController pushViewController:mvc animated:YES];
[mvc release];
}
When you enter the viewControllers in your tabBar, make sure to wrap them inside a UINavigationControllers, otherwise you would not be able to use push and pop functionalities.
Upvotes: 1
Reputation: 1423
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger theIndex;
[self.tabBarController setSelectedIndex:theIndex];
}
Upvotes: 2