2010-12-09 73 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。 (這是我從中學到了這個了不起的模式的人。)

至於使用點符號與不是,那麼,這是一個完全不同的討論。因人而異。 ;)

相關問題