uitabbarcontroller中的取消突出显示的uitabbaritem [英] unhighlight uitabbaritem in uitabbarcontroller

查看:55
本文介绍了uitabbarcontroller中的取消突出显示的uitabbaritem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有5个选项卡按钮的UITabBarController.在某些活动中,我想取消所有选项卡蝙蝠项目的显示.

I have UITabBarController having 5 tabbar buttons. On some activity I want to unhighlight all the tab bat items.

任何人都可以帮忙吗?

谢谢

安吉塔

推荐答案

首先,我想说取消选择所有tabbaritems会带来糟糕的用户体验.很有可能不被应用程序商店接受.

First of all, I'd like to say that unselecting all tabbaritems is a bad user experience. Chances are high that it won't be accepted into the appstore.

在我说完之后,我找到了答案这里.您可以接受此答案(如果可行!!!),但应向该用户提供道具.他在键值观察"中使用了一个技巧,并使用了以下代码:

After I said that, I found the answere here. You can accept this answer (if it works!!!) but props should be given to that user. He used a trick in Key Value Observing, and used the following code:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     
    // Create the view controller which will be displayed after application startup     
    mHomeViewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];      
    [tabBarController.view addSubview:mHomeViewController.view];     
    tabBarController.delegate = self;     
    [tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:NULL];      
    // further initialization ... 
}  

// This method detects if user taps on one of the tabs and removes our "Home" view controller from the screen. 
- (BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {     
    if (!mAllowSelectTab)     
    {         
        [mHomeViewController.view removeFromSuperview];         
        mAllowSelectTab = YES;     
    }      
    return YES; 
}  

// Here we detect if UITabBarController wants to select one of the tabs and set back to unselected. 
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {     
   if (!mAllowSelectTab)     
    {         
        if (object == tabBarController && [keyPath isEqualToString:@"selectedViewController"])         
        {             
            NSNumber *changeKind = [change objectForKey:NSKeyValueChangeKindKey];              
            if ([changeKind intValue] == NSKeyValueChangeSetting)             
            {                 
                NSObject *newValue = [change objectForKey:NSKeyValueChangeNewKey];                  
                if ([newValue class] != [NSNull class])                 
                {                     
                    tabBarController.selectedViewController = nil;                 
                }             
            }         
        }     
    } 
}

他添加了以下注释:

标签栏中的第一个视图控制器仍然会加载(尽管对于很短的时间),因此其viewDidLoad并且viewWillAppear将被调用启动后.您可能要添加一些逻辑,以防止一些您可能会在其中进行初始化这些功能直到真实"显示由于用户而导致该控制器的状态点击(例如使用全局变量或NSNotificationCenter).

the first view controller from tabbar still will be loaded (although for a very short time), so its viewDidLoad and viewWillAppear will be called after startup. You may want to add some logic to prevent some initializations you probably may do in these functions until "real" display of that controller as a result of user tap (using for example global variables or NSNotificationCenter).

这是用于修改Apple-UITabbar.您还可以创建自定义UITabbar.

this is for adapting the Apple-UITabbar. You can also create a custom UITabbar.

这篇关于uitabbarcontroller中的取消突出显示的uitabbaritem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆