How can I hide the toolbar of a UINavigationController using storyboards?

喜夏-厌秋 提交于 2019-12-07 01:40:12

问题


I have a storyboard iOS app that has a number of views I push through. I have a UINavigationController with the "Shows Toolbar" option selected, which then populates throughout my view hierarchy.

Say my view flow is 3 views, A, B, and C:

View A --(push)--> View B --(push)--> View C

View A is a normal view controller, with a button on the toolbar used to push View B. View B is a table controller, so I want to hide the toolbar here. View C is another view like View A, with a toolbar required to be shown.

In Xcode/Storyboard, if in View B I select the "Hides bottom bar on push" it does exactly that - the bottom bar is hidden for View B. Similarly if I choose 'None' for the 'Bottom bar' select option, there's no bar for View B. Good.

Here's my problem: No matter what I do, using either option for view B, my toolbar doesn't come back for view C. If I set View C's toolbar as inferred (and uncheck hide on push) it doesn't show, nor if I set it manually to 'Toolbar'.

Any ideas?


回答1:


As @Zoltán said, Storyboard doesn't provide the complete answer.

Setting self.navigationController.toolbarHidden = YES/NO on viewDidLoad or viewWillAppear is functional, but ugly (a black rectangle appears in place of the toolbar during the view transition animation).

Here's what I did for the View B controller (and the inverse for View C) to mimic the animation smoothness of the "hide on push" option in the storyboard:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:YES];
}



回答2:


I dont think you can do it purely in The Storyboard. However you can just set it to display always, put the buttons on it for every view you want it to appear in and you can call self.navigationController.toolbarHidden = YES; when a viewcontroller is loaded in which you dont want the toolbar to appear. After that if another VC appears on which you do want the toolbar, just set toolbarHidden to NO.



来源:https://stackoverflow.com/questions/11840629/how-can-i-hide-the-toolbar-of-a-uinavigationcontroller-using-storyboards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!