views:

372

answers:

1

My question is about how to access the TabBarController from within one of its viewControllers.

Imagine a mainClass.m that adds tabBarController which has two viewControllers - viewController1 and viewController2.

In viewController1.m there is a game. When the game is over, viewController1.m wants to tell tabBarController to display viewController2, but viewController1 has no reference to tabBarController. How do I reference the viewController's parent?

How does one change tabBarItems from within the code for the current view?

+3  A: 

Via the tabBarController property of your view controller.

[ self.tabBarController setViewControllers: viewController2 animated: YES ];

Where "self" is viewController1

tabController property of viewControllers

setViewControllers:animated: method of UITabBarController

Also, technically, the tabBarController is not any view controller's parent. To say it that way is confusing how inheritance works in Objective-C. Your view controller's super class, or parent, is UIViewController.

apphacker
Thank you. That's fantastic that is is built into the viewController.
Bryan
If it works for you, please don't forget to pick me as the answer. :P
apphacker
You got it. I wasn't sure how the parent child thing worked.
Bryan