Reputation: 2640
I have a tab bar application with several tabs, and all that is no problem. Each tab goes to a new page and opens a new view.
What I want to do is add a tab that does NOT open up a new page or a new viewcontroller, but pops up a picker view on top of the current page. Selecting an option from that picker will then jump to the new view.
So in the tabs:
page 1 / page 2 / page 3 / picker
Any of the first 3 tabs immediately jump to the new page. The 4th tab opens up the picker with options of page 4 / page 5 / etc, and picking one of those then goes to that page.
If you cancel the picker view, the app stays on the current page / tab.
Is this technically possible to do, and is such behaviour allowed within Apple guidelines?
Upvotes: 0
Views: 519
Reputation: 10175
First of all, regarding the Apple guidelines this is allowed because you can decide if the app should load a new view controller when the user taps on a UITabBarItem, but showing a UIPickerView when the user taps on a UITabBarItem is not intuitive and doesn't conforms with the apple UI patterns. Basically, the tab bar items are used for displaying the most important features of your applications and I think a piker view is not one of them.
But if you don't care about the apple UI patterns (which is not ok :)) ) you can use the method posted by darkfoxmrd
.
Upvotes: 2
Reputation: 1751
You will need to subclass UITabBarController, and implement this method:
- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController
{
NSInteger tabIndex = [[tbController viewControllers] indexOfObject:viewController];
//Check to see if the selected index is the one you want to do something else, in this example, it's the second tab, so index is 1
if(tabIndex == 1)
{
//Write the code you need to pop up the picker here.
return false;
}
return true;
}
This will prevent the tab bar from actually showing a new view controller, and instead you can code it to do whatever you want. Note that you will still have to have some kind of placeholder view controller for that tab, even though you will never view it. It just needs to hold a place so the tab bar controller knows it needs to have a tab for it.
Upvotes: 4