1

I have five tabs on the tab bar controller. By default the first view is shown. Is there a way to prevent the user from tapping the other tabs if a pre-condition is not met?

Currently, in my app, I check for the pre-condition, and an alert is shown - however, after the view is switched.

Sam.

1 Answer 1

1

Use the UITabBarControllerDelegate method:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if (_precondition){
        return YES;
    } else {
        [[[UIAlertView alloc] initWithTitle:@"Hey!" message:@"Learn to meet your preconditions!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Sorry Chum", nil] show];
        return NO;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.