Search code examples
iphoneclickactiontabbarcontroller

How to change the action of the first tabbaritem (when clicked)


I'm trying to show a tableviewcontroller as the first page, with the tabbarcontroller in it. After it is shown I would like to change the action of the first item in the tabbarcontroller to show a menu.

I have created the menu, I only need to find a way to change the click event of the first item on the tabbarcontroller.

I've been searching for hours now, and help would be greatly appreciated!

Thanks in advance, Tommy

*edit: I found the solution, I will post it tomorrow!


Solution

  • I found out a good way to handle this problem...

    I used the UITabBarController delegate and implemented this:

     - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
      if([viewController.title isEqualToString:@"YourTitleHere"])
      {
         // do your stuff here
      }else
      {
         return YES;
      }
    }
    

    this Worked great for me, very happy that I finally found a solution! Hope this helps others as well!