在 UITabBar 中不选择任何选项卡 [英] Select no tabs in a UITabBar

查看:14
本文介绍了在 UITabBar 中不选择任何选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中完全不选择任何选项卡.首先选择了第一个选项卡,但我想取消选择它,因此根本不会选择任何选项卡.

I'm trying to select no tabs at all in my application. At first the first tab is selected, but I'd like to deselect it so no tabs at all would be selected.

不要问我为什么,这就是客户想要的!呵呵

Don't ask me why, it's just that way the client wants it! hehe

感谢您的帮助!

PS:我已经试过了:

// rootController = UITabBarController    
rootController.tabBar.selectedItem = 0;
rootController.tabBar.selectedItem = nil;
[rootController setSelectedIndex:[rootController.items objectAtIndex:0]];
[rootController setSelectedIndex:nil];
[rootController setSelectedIndex:0];
// That one works : (but I can't select 0 or -1 for instance)
[rootController setSelectedIndex:2];

有什么想法吗?再次感谢!

Any ideas? Thanks again!

推荐答案

如果你使用的是没有 UITabBarController 的 UITabBar 实例,你可以取消选择所有标签栏项目.

You can deselect all tab bar items if you are using UITabBar instance without UITabBarController one.

在这种情况下,下面的代码运行良好.

In such case below code works well.

[tabBar setSelectedItem:nil];

如果 UITabBar 是 UITabBarController 的一部分,那么应用程序将崩溃并出现异常:

If UITabBar is a part of UITabBarController then application will crash with exception:

'直接修改管理的标签栏通过标签栏控制器不是允许.'

'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

换句话说,如果您想完成这项工作,您需要在没有控制器的情况下手动管理标签栏的例程.

In other words if you would like to get this worked you need to manage tabbar's routines manually without controller.

这篇关于在 UITabBar 中不选择任何选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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