views:

151

answers:

2

I am developing an iPhone app that displays several views, all acessed via Tab Bar items. However I need to add an additional item to the Tab Bar that simply launches a URL in Safari.

I've accomplished this by adding an empty placeholder view to the TabBar and returning FALSE from shouldSelectViewController when the this view's tabBarItem is clicked on, and launching Safari at the same time.

That code is:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
 if([[viewController tabBarItem] title] == "Website"){
            //... launch Safari
  return FALSE;
 } else {
  return TRUE;
 }
}

PROBLEM: If the TabBar has too many items, and this "Safari Launch" tab is pushed off to the "More" navigation controller, I lose the capability to intercept the event and prevent the view from loading when clicked.

Any suggested tips?

+1  A: 

You might consider having that tab simply display a UIWebView with the web site.

I second glorifiedHacker in that having a tab bar item quit the application and launch another is not expected behavior.

Frank Schmitt
I agree. I'm redesigning so that the Tab Bar continues to manage views, as expected. I'll create a new view that contains a button to launch the external URL.
Chris Schnyder
A: 

My idea is, if you do not allow the users to customize the tab bar items, "Safari Launch" being pushed to "More" will never happen. You can prevent editing by setting the customizableViewControllers of your tab bar to nil or an empty array.

zonble