在我的 iOS 应用程序中,我的 Storyboard上有以下 View Controller 导航方案
Navigation Controller -> ViewController A -> ViewController B
我可以在 View Controller A
上自定义导航栏,但我在 Interface Builder 上设计的自定义导航栏不会显示在 View Controller B
上。它只显示“后退”按钮。
我可以为界面生成器上的“内部” View 定义自定义导航栏吗?我知道我可以通过编程方式完成它,但如果我能避免它,那就更好了。
最佳答案
我认为您在理解过程中可能遗漏了一个重要元素。
UINavigationController
拥有的 UINavigationBar
只是每个 View Controller 的 UINavigationItem
的容器。使用此导航项添加/删除特定于每个 View Controller 的按钮。
使用你自己的例子:
UINavigationController
(displays each view controller's navigation item inside its navigation bar) ->UIViewController
A (includesUINavigationItem
A, which has its own buttons) ->UIViewController
B (includesUINavigationItem
B, which has its own buttons)
如果您想隐藏后退按钮,您可以通过在每个 View Controller 或 View Controller 的父类(super class)中添加以下行来实现:
self.navigationItem.hidesBackButton = true
如果您希望所有 View Controller 都具有相同的按钮,您最好创建一个 UIViewController
基类并以编程方式将适当的按钮添加到导航项。确保你所有的 View Controller 都继承自这个新的子类。
希望这对您有所帮助!
关于ios - 如何覆盖 "default"导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33567251/