Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabBarControllerDelegate method not getting called

I have a tab bar controller which has 4 tabs, I want: when tap the 4th tab(a dummy viewcontroller), it will present a new viewcontroller without showing the dummy VC.

here is my code:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSLog(@"called");
    AskQuestionViewController *AQVC = [[AskQuestionViewController alloc]initWithNibName:@"AskQuestionViewController" bundle:nil];
    if (viewController == [tabBarController.viewControllers objectAtIndex:3])
    {
        [self presentViewController:AQVC animated:YES completion:nil];
        return NO;
    }
    return YES;
}

and in my viewDidLoad method, i did set the delegate.self.tabBarController.delegate = self;

however, for some reason, this method is not being called. can anyone help?

like image 516
One Eyed Raven Avatar asked Jul 24 '15 13:07

One Eyed Raven


1 Answers

because this class is a tabBarController, clearly a UITabBarController class doesn't have a property called tabBarController.

So I just changed self.tabBarController.delegate = self to self.delegate = self

like image 190
One Eyed Raven Avatar answered Oct 18 '22 10:10

One Eyed Raven