Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch a modal view from a custom UITabBar?

I've built out the raised-center UITabBar from this GitHub location.

My challenge now is that I can't figure out how to create a modal view that will appear when the button is pressed.

Has anyone used the idev-recipes RaisedCenterTabBar with luck? How did you implement the modal sheet that appears there?

Alternatively, is there a different gitHub project that has a working custom tab bar with a modal sheet?

Thank you!

like image 766
bryanjclark Avatar asked Dec 13 '25 05:12

bryanjclark


1 Answers

Here was my solution, it was BY FAR the cleanest way I found to do this... I really hope it helps, I spent hours researching the best ways.

I setup a "UITabBarController" delegate that connects directly to my tab interface built out on my storyboard.

** Don't forget to include the "tabBarController" delegate in your header file

** Notice this callback method is NOT the "didSelectViewController" but rather the "shouldSelectViewController". This method handles the request before the tab is selected and that is exactly what you want so you can STOP the request before it ever happens... This way you don't have to save the current index you are on, pass it around and all that nonsense.

Then I am simply checking what tab WILL be selected (based on the view controller's title.

** Also: this is my code, change it as needed for your code. But the principals should remain. My "performSegueWithIdentifier" is actually a manual segue connected to my tab controller that opens in a modal. This code is working brilliant for me.

 -(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

     if([[viewController title] isEqualToString:@"tellvc"])
     {
         [self performSegueWithIdentifier:@"shareModelViewController" sender:Nil];
         return NO;
     }
     else
     {
         return YES;
     }

 }
like image 130
rckehoe Avatar answered Dec 15 '25 04:12

rckehoe