iphone - 导航 Controller 中的工具栏

标签 iphone objective-c ios uinavigationcontroller

我正在使用以下代码在导航 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/

相关文章:

iphone - 验证具有特殊字符的文本字段

iphone - 在 Iphone 中动态创建 XML 文件

ios - 我应该使用 Mac 来测试 iPhone 还是 Windows 就足够了?

objective-c - 在 AVAudioRecorder 中获取 channel 的 AveragePower 和 PeakPower

ios - 如何在 Xcode 中以编程方式获取夏令时设置?

ios - 为什么我的 NSURLSessionDownloadTask 下载无法到达我的客户端?

ios - 在 iOS 中以后台模式将数据从 Central 传输到外围设备

iphone - iOS —将方法映射到数组

ios - 根据所选的 MKAnnotationView 动态更改 leftCalloutAccessoryView

ios - 增加或减少 float