Currently I have a UITabBarController with 4 items on it that all have associated view controllers. I’d like to add a 5th tab bar item that does not go to a new view controller, but rather launches a website in Safari. Essentially, it acts like a UIButton.
So the behavior would be:
User is on tab 1.
User clicks on tab 5 (tab 5 turns blue for an instant).
View does not change.
Website opens in Safari (I know how to do this part)
When user returns to the app, they are still on tab 1 (tab 1 is blue)
Any ideas?
Currently my UITabBarController is setup like this (where localControllerArray is an array of 4 UINavigationControllers):
tabBarController.viewControllers = localControllersArray;
[localControllersArray release];
[self.window setRootViewController:tabBarController];
[tabBarController release];
You know how the
UITTabBarControllerhas a delegate property? Create an object that implements theUITabBarControllerDelegateprotocol, and set it as a delegate. Then, when you select any of the tabs, delegate’s tabBarController:didSelectViewController: will get called. In it you can check to see if your 5th tab was tapped. In that case, simply set theselectedIndexproperty of the tabbarcontroller to what you want. That’s it.PS, Actually you should just call tabBarController:shouldSelectViewController:
instead this way the view won’t switch.