1

我在标签栏控制器上有五个标签。默认情况下显示第一个视图。如果不满足先决条件,有没有办法阻止用户点击其他选项卡?

目前,在我的应用程序中,我检查前提条件,并显示警报 - 但是,在切换视图之后。

山姆。

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 回答