1

I need to intercept a UITabBar tap precisely so I can conditionally abort moving to the intended ViewController (i.e. conditionally dismiss the tap).

I create my UITabBar in the storyboard. The UITabBar is the root view of my entire app. One of the tabBar items is a profile page (so to speak). If a user does not yet have an account, I want to ignore their clicking on that specific tabBar item. The behavior I seek is that the user will not leave the present ViewController they are in to go to the Tab selected. But instead, I want them to segue to the registration page. Any ideas how I might do this interception?

UPDATE

I have managed to add the following method in my AppDelegate. The method is called, but the transition is not intercepted. How do I intercept and abort the transition?

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"Intercept tabBarController in app delegate tap gesture but then do nothing");
}

The NSLog line is printed, but transition still occurs.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • what about disable the actual tab-bar item? or you want to redirect the user to the sing-up page in every time when there is no account has been set yet? – holex Aug 22 '14 at 11:55

2 Answers2

1

Sounds like you are on the right path. But you should use

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

If you need more help, let me know.

Konsol Labapen
  • 2,424
  • 2
  • 15
  • 12
0

You need to go with the UITabBar delegate of tabBar:didSelectItem:

Ex:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
   // Use the item to do further
}
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
  • I tried putting the method in the app delegate and then in the present view controller but the method is never called. Are you able to provide a fuller sample? – Katedral Pillon Aug 22 '14 at 11:54