[英]UITabBarController with UINavigationController
我在UITabBarController(選項卡1)中有一個UINavigationController。 進入第二個視圖(仍在選項卡1中)時如何使選項卡欄消失? 我可以使用“后退”按鈕向后導航,然后標簽欄將重新出現。
self.hidesBottomBarWhenPushed = YES; 將此行放置在導航的位置(在進行推送操作之前)。
和self.hidesBottomBarWhenPushed = NO; 在viewWillDisappearing從您推其他視圖的同一頁面。
真的行。
在要推送的viewController中,放入:
self.hidesBottomBarWhenPushed = YES;
在-viewDidLoad
方法中。 它屬於“子” VC,而不是進行推送的VC。 您無需在其他任何地方進行設置。
我喜歡使用視圖控制器的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時,您的底部欄將返回。 (諾言。)
這項技術應歸功於Big Nerd Ranch的Joe Conway。 (這就是我從中學到的一種很棒的模式。)
至於使用點符號與不使用點符號,那是完全不同的討論。 YMMV。 ;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.