iPhone,我如何隐藏标签栏按钮? [英] iPhone, how I hide a tab bar button?

查看:179
本文介绍了iPhone,我如何隐藏标签栏按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏单个标签栏按钮?

How do I hide an individual tab bar button ?

我搜索过但没有找到任何内容,只有完整的栏。

I've searched and not found anything, only the full bar.

我已经取得了一些进展但仍然遇到问题,这段代码在我的app委托中,有一个显示标签栏的插座,我在 viewDidLoad

I've made some progress but still having problems, this code is in my app delegate with an outlet to the tab bar, I'm calling it within viewDidLoad of the first view shown in tab bar.

-(void)hideTabButton {  
NSMutableArray *aItems = [[rootTabBar items] mutableCopy];
for (UITabBarItem *tabButton in aItems) {
    if ([tabButton.title isEqualToString:@"First"]) {           
        [aItems removeObject:tabButton];
        break;
    }
}
[rootTabBar setItems:aItems animated:YES];
[aItems release];   
}

但是这给了我一个错误,看起来确实有可能为什么有 setItems

But this gives me an error, it does seem to be possible otherwise why have setItems.

 Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Directly modifying a tab bar managed by a tab bar controller is 
not allowed.'
Call stack at first throw:

继承我的完整代码,认为我很接近。
我的示例项目

Heres my full code, think I'm close. My Sample project

推荐答案

您需要使用 setItems:animated:来执行此操作。创建一个要保留在UITabBar上的按钮数组,并将其传递给此实例方法:

You would need to use setItems:animated: to do this. Create an array of the buttons you want to keep on the UITabBar and pass it to this instance method:

[myTabBar setItems:itemsToKeep animated:TRUE];

参考: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBar_Class/Reference/Reference.html

这篇关于iPhone,我如何隐藏标签栏按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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