导航控制器中的工具栏 [英] Toolbar in Navigation Controller
问题描述
我使用以下代码在导航控制器中创建工具栏:
I am creating a toolbar in a Navigation Controller using the following code:
[self.navigationController setToolbarHidden:NO];
//Create a button
NSArray *toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStyleBordered target:self action:@selector(helpButton:)]
,nil];
唯一的问题是,只要有导航控制器(多个其他视图),工具栏就会可见。有没有办法只将工具栏限制在一个视图?
The only problem is that the toolbar is visible whenever there is a navigation controller(multiple other views). Is there a way to only restrict the toolbar to a single view?
谢谢
推荐答案
引用 UINavigationController类参考 :
导航工具栏默认隐藏但您可以显示导航工具栏接口通过调用导航控制器对象的
setToolbarHidden:animated:
方法。如果并非所有视图控制器都支持工具栏项,则委托对象可以调用此方法以在后续推送和弹出操作期间切换工具栏的可见性。
The navigation toolbar is hidden by default but you can show it for your navigation interface by calling the
setToolbarHidden:animated:
method of your navigation controller object. If not all of your view controllers support toolbar items, your delegate object can call this method to toggle the visibility of the toolbar during subsequent push and pop operations.
因此,请为导航控制器设置一个委托。在你的委托的 navigationController:willShowViewController:animated:
中,做这样的事情:
So, set a delegate for your navigation controller. In your delegate's navigationController:willShowViewController:animated:
, do something like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
BOOL shouldShowToolbar = (viewController == theViewControllerThatNeedsAToolbar);
[navigationController setToolbarHidden:shouldShowToolbar animated:animated];
}
这篇关于导航控制器中的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!