Reputation: 1011
I am presenting a UITabBarController
from another ViewController
(HomeViewController). The TabBarController
in turn contains UINavigationControllers
. However, when from one of the navigation controllers, the user presses the home button, he is required to go to the original ViewController
from where the TabBarController
was presented.
**tabBarController
is not the rootViewController of my window.
Here's my code.
In AppDelegate
, I am creating and configuring my TabBarController
.
self.custCareVC = [[CustomerCareViewController alloc] initWithNibName:@"CustomerCareViewController_iPhone" bundle:NULL];
self.POController = [[PurchaeOrderViewController alloc] initWithNibName:@"PurchaeOrderViewController_iPhone" bundle:NULL];
self.accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:@"AccountsAndContactsViewController_iPhone" bundle:NULL];
self.customerCareNavController = [[UINavigationController alloc] initWithRootViewController:self.custCareVC];
self.customerCareNavController.title = @"Customer Service";
self.purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:self.POController];
self.purchaseOrderNavController.title = @"PO";
self.accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:self.accAndContactsController];
self.accAndContactsNavController.title = @"Accounts And Contacts";
self.tabBarController = [[UITabBarController alloc] init];
//self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"bluehead.png"];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.customerCareNavController, self.accAndContactsNavController, self.purchaseOrderNavController, nil];
In my HomePageViewController, i am presenting it in the following way (on click of a button):
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
appDel.tabBarController.delegate = self;
[self presentViewController:appDel.tabBarController animated:YES completion:NULL];
Now i need to dismiss my tabBarController after a user presses a Button on any of the navigation controllers (present in the tabBarController) and show the HomeViewController again..!!
Upvotes: 1
Views: 1474
Reputation: 1801
You need to create a function in your target controller (which has the power to dismiss the tabBarController
) and call that function from your topmost(current) controller/ controller the user is currently interacting with. To achieve the above, you need to first get the tabBarController
object from the current controller using parent view controller. Then get the parent view/ root view controller of that controller and performSelector
(function) which you created in the first controller.
Be sure to check doesRespondToSelector
before you call performSelector
so as to avoid any nasty crashes.
Another way, though pretty hackie is to store a weak reference of the first controller in the AppDelegate and access the same from you current controller.
Upvotes: 1