UINavigationController 的 children 视图没有 UINavigationItem 来设置标题
UINavigationController's children views don't have UINavigationItem to set the title
我实施了 UINavigationController
以具有 pop/push 的功能。但是,在 children 视图中,我无法设置导航栏的标题,而只能在第一个视图中设置:
在上面看到的 "Buzzy" 页面上,当我 select 导航栏时,实用程序选项卡显示它是一个 UINavigationItem
,我可以编辑它的标题。但是,在其中一个 children 视图中,例如带有 "Tappable Area" 的视图,无法 select 编辑导航栏并且无法添加标题。
如何为 children 次观看添加标题?
将导航项 object 从 Objects 面板 (cmd-shift-L) 拖到视图控制器上,然后 select 它。
您现在应该可以设置标题、添加 UIBarButtonItems 等
尝试 self.navigationItem.title = "Your title"
通常这是在视图加载到视图控制器时完成的:
override func viewDidLoad() {
super.viewDidLoad()
self.title = "some title"
}
但是,这仅在您将视图控制器嵌入到 UINavigationController 中时才有效。我强烈建议这样做而不是自己创建导航栏。如果您坚持自己创建导航栏,您可以通过以下方式更改标题:
navigationBar.topItem.title = "some title"
我实施了 UINavigationController
以具有 pop/push 的功能。但是,在 children 视图中,我无法设置导航栏的标题,而只能在第一个视图中设置:
在上面看到的 "Buzzy" 页面上,当我 select 导航栏时,实用程序选项卡显示它是一个 UINavigationItem
,我可以编辑它的标题。但是,在其中一个 children 视图中,例如带有 "Tappable Area" 的视图,无法 select 编辑导航栏并且无法添加标题。
如何为 children 次观看添加标题?
将导航项 object 从 Objects 面板 (cmd-shift-L) 拖到视图控制器上,然后 select 它。
您现在应该可以设置标题、添加 UIBarButtonItems 等
尝试 self.navigationItem.title = "Your title"
通常这是在视图加载到视图控制器时完成的:
override func viewDidLoad() {
super.viewDidLoad()
self.title = "some title"
}
但是,这仅在您将视图控制器嵌入到 UINavigationController 中时才有效。我强烈建议这样做而不是自己创建导航栏。如果您坚持自己创建导航栏,您可以通过以下方式更改标题:
navigationBar.topItem.title = "some title"