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.

4

1 に答える 1

1

UITabBarControllerDelegate次の方法を使用します。

-(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;
    }
}
于 2012-11-18T02:42:01.980 に答える