开发者

Objective C: How to disable user interaction to all of tab bars except one?

开发者 https://www.devze.com 2023-03-27 20:41 出处:网络
As what the title suggests, I would like to be able to lock all my tab bars except for one. And only after the user completes an action will I enable all the rest开发者_如何学Go of the tab bars. How c

As what the title suggests, I would like to be able to lock all my tab bars except for one. And only after the user completes an action will I enable all the rest开发者_如何学Go of the tab bars. How can I do that?


I haven't tried it, but according to the docs, you can return NO from the tabBarController:shouldSelectViewController: delegate.

[UPDATE] I just tried that out of curiosity - it seems to work fine. Create a new project from the "Tab bar application" template and then go to the -viewDidLoad of your FirstViewController. Add this line:

[self.tabBarController setDelegate:self];

and then implement the delegate method:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (userHasCompletedAction) {
        return YES;
    }
    return NO;
}

Don't forget to conform to <UITabBarControllerDelegate> in your .h file!

Hope that helps.


You have to implement this method

- (void)tabBarController:(UITabBarController *)tabBarController1 didSelectViewController:(UIViewController *)viewController {

    if ([tabBarController1 selectedIndex]==0) { 
        UITabBarItem *tabBarItem = [[[[self tabBarController]tabBar]items] objectAtIndex:1];
        [tabBarItem setEnabled:FALSE];

    } 
}

You have to do something like this for disabling your required tabbar items.


The method tabBar:didSelectItem: in UITabBarDelegate could help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号