views:

353

answers:

1

In have a UITabBarController with 3 view controller subviews. The default subview for the app is viewOne (with viewControllerOne). The other two are viewTwo and viewThree with the ordering in the UITabBar as expected.

My objective is to have an action be done when viewTwo is selected in the UITabBar while viewOne is active.

The viewTwo view is never shown but instead, when viewTwo is selected, an action is performed in viewTwoController, the UITabBar then shows viewOne as selected and the orignal view is shown again.

The UITabBarItem in the second slot must remain associated with the viewTwo nib.

Is it possible to associated a UITabBarItem with an action in its view controller and upon finishing that action, instruct its parent UITabBarController to switch to a different view?

+1  A: 

UITabBarControllerDelegate got a method called tabBarController:shouldSelectViewController that you can override to do whatever you want to do when a tab switch has been triggered.

Here is the documentation: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarControllerDelegate%5FProtocol/Reference/Reference.html#//apple%5Fref/occ/intfm/UITabBarControllerDelegate/tabBarController%3AshouldSelectViewController:

nico
I still want code in the view controller to execute, though, so this doesn't help. 1)View1 is selected by default 2)View2 selected 3)Code in View2Controller executed 4)When code in View2Controller done, open View1 again.
Mat
On OS 3.x, you could use selectedViewController of your tab controller to programatically force the selection of your View1 when you're done in View2
nico
Setting ((UITabBarController *)self.parentViewController).selectedIndex = 0 in a selector in viewControllerTwo selects the tab corersponding to viewControllerOne on the UITabBarController bar, but the view appears to be blank. I know a view is associated with the view controller, as I start the app by viewing this controller. What would be causing the tab to be selected but the view to not be displayed? If I instead set the selectedViewController attribute and reference the UITabBarController's viewController NSArray, I get the same result. Help!
Mat
http://stackoverflow.com/questions/1297658/iphone-view-doesnt-update-with-uitabbarcontroller-when-changing-tabs-programatic
nico