3

我有一個似乎很簡單的問題。 我的應用程序具有包含UITabBarController(包含UINavigationControllers)的視圖層次結構。當我從根源定位到第二級 我設置上真正的hidesBottomBarWhenPushed使標籤欄被隱藏hidesBottomBarWhenPressed,但彈出時

在我firstLevelController:

[secondLevelController setHidesBottomBarWhenPushed:YES]; 

[self.navigationController pushViewController:secondLevelController animated:YES]; 

後,當我推到第三級,我

[self setHidesBottomBarWhenPushed:NO]; 

[thirdLevelController setHidesBottomBarWhenPushed:NO]; 

[self.navigationController pushViewController:thirdLevelController animated:YES]; 

(我知道,我不喜歡[self setHidesBottomBarWhenPushed:NO]要麼,但它didn't工作,否則......)

0:由secondLevelController做再次把標籤欄

所以,這裏是問題:當我在第三級按下後退按鈕並出現第二個視圖時,我需要再次隱藏tabbar,但是我無法找到這樣做的方式。

任何幫助表示讚賞

+3

我不認爲這是一個支持的用例。讓標籤欄重新出現在堆棧層次結構中更深層次是沒有意義的。你可能想重新考慮你的設計。 – 2011-04-06 17:25:44

回答

12

這是對我有用的東西。

[self setHidesBottomBarWhenPushed:NO]; 
[thirdLevelController setHidesBottomBarWhenPushed:NO]; 
[self.navigationController pushViewController:thirdLevelController animated:YES]; 
[self setHidesBottomBarWhenPushed:YES]; 

thirdlevelController顯示tabbar,secondLevelController在彈出thirdLevelController時不顯示tabbar。

+0

從目標視圖控制器中設置它是最容易的,並且可以改善分區。 viewDidLoad通常可能爲時已晚,所以我從init或通過覆蓋hidesBottomBarWhenPushed來設置它,並返回YES或NO。 – 2011-12-28 14:29:05

+1

非常感謝你!我浪費了許多小時來解決這個問題......沒有它就無法完成......:D:D – Nishant 2012-09-05 17:08:56

+0

它爲什麼會起作用? – 2015-11-05 08:21:51

-1

你可以試試這個

您在secondLevelController

static BOOL bottomBarShouldHide = YES; 

在viewDidLoad中聲明,

if (bottomBarShouldHide) { 
    [secondLevelController setHidesBottomBarWhenPushed:YES]; 
    bottomBarShouldHide = NO; 
} 
else { 
    [secondLevelController setHidesBottomBarWhenPushed:NO]; 
    bottomBarShouldHide = YES; 
} 

我希望它可以幫助你。

0

如果您是來自popViewController 並且在viewDidAppear中,您可以持有一個bool值以瞭解它是否會再次隱藏您的選項卡欄。

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    if(backFromThirdView) 
    [self setHidesBottomBarWhenPushed:YES]; 
    else 
     [self setHidesBottomBarWhenPushed:YES]; 

}

0

我其實是同樣的問題。我總是嘗試在選擇一行時隱藏tabbar,並在返回列表(導航控制器中的tableview)後禁用隱藏,以便用戶可以再次選擇菜單。我設置隱藏方法

-(void)tableView:(UITableView *)tableView 
      didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

內tabbarcontroller但是當我牆根它這個方法裏面,再返回到我的列表時使用TabBar還在牆根。現在

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ 

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 

    if (self) { 
     // Custom initialization 
    } 

    [self setHidesBottomBarWhenPushed:YES]; 

    return self; 
} 

當我選擇一個列表項,這個視圖控制器將提交的TabBar的牆根,回國後:現在我隱藏特定視圖控制器的init方法裏面Tabbarcontroller,也許這個作品爲別人太該列表再次出現。

5

在您secondViewController,做到:

- (BOOL) hidesBottomBarWhenPushed { 
    return ([self.navigationController.viewControllers lastObject] == self); 
} 

這樣一來,使用TabBar將始終當你是在secondViewController隱藏,它會出現在其他視圖控制器

+0

非常感謝你.. – krishnanunni 2016-01-28 10:45:00

+0

當你需要讓選項卡消失並稍後在導航堆棧中重新出現時,這很有效。謝謝! – jbolter 2016-07-13 21:14:08