1

When the user triggers a tabbar item I want to display present a modal view controller.

I have something working but it's probably not the cleanest way to do it. It also prevents the UITabBarItem to be in selected state.

What I did is setting this method to false and in the that method body presenting the view controller (via the RootViewController).

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    UINavigationController *nvc = (UINavigationController*)viewController;

Do you guys have any idea of a cleaner implementation of this that would allow the TabBarItem to be highlighted ?

BrainOverfl0w
  • 257
  • 1
  • 3
  • 13

1 Answers1

0

This is the one of the way to use the MVC on Tab bar...To highlighting the tab bar item like that.

id currentlySelected; //This will hold the address of the selected view id dontAllowSelection; //This will hold the address of the Denied view

  • (BOOL)tabBarController:(UITabBarController *)tabBarControllers shouldSelectViewController:(UIViewController *)viewController

{

if (dontAllowSelection != nil && //If it is nil, we will skip it. dontAllowSelection == viewController) //If the selected view is Denied return NO {

return NO;

}

currentlySelected = viewController;

if (currentlySelected == someViewIWantToDisableOtherFor) //Any logic can go here to enable the Denied View.

{
    dontAllowSelection = anotherViewIWantDisabled; //Set my denied view.

}

else
{

    dontAllowSelection = nil; //Unsed the Denial.
}

return YES;

}

iCrazyDev
  • 925
  • 5
  • 16