隐藏标签栏xcode for iphone

时间:2012-12-02 08:54:09

标签: iphone xcode uitabbarcontroller

我正在创建一个基于TabBar的应用程序,我在第二个选项卡中有4个选项卡我有一个UICollectionView控件来显示来自RSS提要的图像。

当用户点击任何图像时,它应该导航到另一个UIViewController中显示有关该图像的更多详细信息。我想在详细信息页面中隐藏TabBar。我尝试了很多方法,但它没有用。

以下是我在UICollectionView

中选择的代码
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    DetailView *detail=[[DetailView alloc] init];
    detail.item= (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detail animated:YES];
    [detail setHidesBottomBarWhenPushed:YES];
    [self.myCollectionView deselectItemAtIndexPath:indexPath animated:YES];
}

我为详细信息页面设置setHidesBottomBarWhenPushed:YES仍然是详细信息页面中显示的标签栏。

我是否应该在这里做任何其他事情。

2 个答案:

答案 0 :(得分:2)

您的DetailView是视图控制器,因为您在self.navigationController推送它。

覆盖viewWillAppear ViewController的viewWillDisappearDetailView方法,作为您添加NavigationController作为TabBarController中的一个视图,您可以直接访问对象tabBarController堆栈的viewcontrollers属于NavigationController

请尝试以下代码:

-(void) viewWillAppear:(BOOL)animated {

    [super viewWillAppear:YES];

    // if you added bottom bar thr xib or thr code on DetailView VC, better if you remove it from DetailView xib
    [self setHidesBottomBarWhenPushed:YES]; 

    // this will hide the Tabbar  
    [self.tabBarController.tabBar setHidden:YES];
}

-(void) viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:YES];

    // this will show the Tabbar  
    [self.tabBarController.tabBar setHidden:NO];
}

答案 1 :(得分:1)

我的初步答案已转换为评论。由于它的缺点,我认为(仅仅是一个外部网站的链接)!

但是,正如您在最后一条评论中详细阐述了您真正需要的内容:如果您想要更改UITabBar的外观,则不一定需要为此目的创建UITabBarController的子类。这取决于您需要的自定义程度,但请先查看Apples“Appearance API”。以下是Ray Wenderlich在User Interface Customization in iOS5网站上发表的一篇很好的文章(也适用于iOS6,该文章附带了一个示例项目)。

Here's通过Appearance API对标签栏自定义进行另一个很好的了解。