-1

我正在寻找一种从 TabBars 选项卡之一的 ViewController 中禁用 TabBarItem 的方法。我什至不确定这是否与视图层次结构或真正要搜索的内容有关。我尝试了很多,但没有提出解决方案。

现在,我通过在实例化选项卡栏(在应用程序委托内)时将对选项卡栏的引用保存在单例对象中来解决它。但我认为这不是最好的方法。

谢谢和干杯,尼尔斯

4

2 回答 2

1

我有同样的问题,我找到了解决方案(但我觉得它有点脏)

在您ViewController要禁用的地方TabBarItem,创建一个UITabBarController *myTabBarController;具有属性的变量。

在您管理的课程中,Tabbarcontroller将此代码放入viewDidLoad

MyViewController * vc = (MyViewController *)[navigationController.viewControllers objectAtIndex:0];// O the index of the first view controller replace it with the index of the needed viewController
vc.myTabBarController = myTabBarController; // pass your TabBarController to your ViewController

现在回到您的ViewController班级(MyViewController)并使用此代码禁用tabBarItem

UITabBarItem *mapTabBarItem= [[myTabBarController.tabBar items] objectAtIndex:1]; // I want to desable the second tab for example (index 1)
[mapTabBarItem setEnabled:NO];  

请注意,这不是最好的方法,但它有效:-)

于 2010-08-31T10:48:05.660 回答
0

也许我不明白你想要什么,但我已经通过进入界面构建器禁用了一个标签栏按钮,然后选择我想要处理的标签按钮(小蓝色突出显示仅在图片的占位符上,带有 ? 的小框)然后 -> 工具菜单 -> 检查器 -> 选项卡栏项目属性(检查器左侧的第一个选项卡)-> 然后底部的一个小单选按钮显示“已启用”-> 取消选择此选项。对我有用,因为我将其用作第一个选项卡上的简单加载屏幕。希望有帮助。柯克

于 2009-10-14T09:19:59.790 回答