2010-12-09 187 views
1

我有UITabBarController(选项卡1)内的UINavigationController。当我进入第二个视图(仍在标签1中)时,如何使标签栏消失?我可以使用后退按钮导航,标签栏将重新出现。UITabBarController与UINavigationController

回答

4

self.hidesBottomBarWhenPushed = YES; 将此行放在您浏览的位置(在推送操作之前)。

and self.hidesBottomBarWhenPushed = NO; 在viewWillDisappear从您推其他视图的相同页面。

它确实有效。在-viewDidLoad方法

self.hidesBottomBarWhenPushed = YES; 

+0

谢谢。是自我的navcontroller? – Adele 2010-12-09 04:40:44

1

在的viewController被推,放。它属于'孩子'风险投资,而不是风险投资。你不需要在其他地方设置它。

0

我喜欢使用视图控制器的init方法来隐藏底部栏等等。使行为更好地封装。

(注:以下是ARC友好的代码,因此没有autorelease来电或retain /release双。)

#pragma mark - UIViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    // We must handle this as it's the designated initializer for UIViewController. 
    // Pay no attention to the params. We're going to override them anyway. 
    return [self init]; 
} 

#pragma mark - NSObject 

- (id)init { 
    // Why hello there, superclass designated initializer! How are you? 
    if ((self = [super initWithNibName:@"YourNibNameHere" bundle:nil])) { 
     // This is a perfect oppy to set up a number of things, such as ... 

     // ... the title (since you're in a nav controller). 
     self.navigationItem.title = @"Your Nav Title"; 

     // ... your bottom bar hiding (takes effect once pushed onto your nav controller). 
     self.hidesBottomBarWhenPushed = YES; 

     // ... and your tab bar item (since you're in a tab bar controller). 
     [self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"Item Title" image:[UIImage imageNamed:@"itemIcon.png"] tag:itemTag]]; 
    } 
    return self; 
} 

现在,所有你需要做的就是alloc/init您的视图控制器,并呼吁-pushViewController:animated:。没有麻烦,没有大惊小怪。

当VC弹出时,您的底栏将返回。 (Promise)

这项技术的信用归于Big Nerd Ranch的Joe Conway。 (这是我从中学到了这个了不起的模式的人。)

至于使用点符号与不是,那么,这是一个完全不同的讨论。因人而异。 ;)

相关问题