我正在使用以下代码在导航 Controller 中创建工具栏:
[self.navigationController setToolbarHidden:NO];
//Create a button
NSArray *toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStyleBordered target:self action:@selector(helpButton:)]
,nil];
唯一的问题是只要有导航 Controller (多个其他 View ),工具栏就可见。有没有办法将工具栏限制为单个 View ?
谢谢
最佳答案
引用UINavigationController Class Reference :
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.
因此,为您的导航 Controller 设置一个委托(delegate)。在您的代表的 navigationController:willShowViewController:animated:
中,执行如下操作:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
BOOL shouldShowToolbar = (viewController == theViewControllerThatNeedsAToolbar);
[navigationController setToolbarHidden:shouldShowToolbar animated:animated];
}
关于iphone - 导航 Controller 中的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303811/