Jonny Vu
Jonny Vu

Reputation: 1428

Show the parent ViewController of a tabbar Item from another ViewController

I have a TabBarController which include 3 tabBar Items. In each TabBar Items include Navigation Controller.

       -> TabBarItem 1 -> Navigation Controller 1
TabBar -> TabBarItem 2 -> Navigation Controller 2
       -> TabBarItem 3 -> Navigation Controller 3

When user work some tasks in TabBarItems 1, some cases should show TabBarItems 2 so i call the following code:

[self.tabBarController setSelectedIndex:1];

But in this case, i want to show the RootViewController of TabBarItems 2. It still not work because the above code could not bring view back to RootViewController.

So how to show the RootViewController of TabBarItem2 in my case

Upvotes: 0

Views: 962

Answers (2)

Hashim Khan
Hashim Khan

Reputation: 440

Try this-

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

Upvotes: 2

Iphone User
Iphone User

Reputation: 1950

Hope that i understand what you need, try something like this

UINavigationController *navController=(UINavigationController*)[self.tabBarController.viewControllers objectAtIndex:0];
[navController popToRootViewControllerAnimated:YES];

hope this will help you

Upvotes: 1

Related Questions