[英]Set title of parent navigation bar
I have a UINavigationController
that pushes a UIViewController
that has its own custom UINavigationBar
. 我有一个
UINavigationController
,它推送具有自己的自定义UINavigationBar
的UIViewController
。 This means there are two UINavigationBar
s showing at once. 这意味着一次显示两个
UINavigationBar
。 I can't seem to set the title of the navigation bar in the navigation controller. 我似乎无法在导航控制器中设置导航栏的标题。
I have tried using this code in the pushed view controller: 我尝试在推送的视图控制器中使用以下代码:
self.title = "A Title"
But it doesn't work. 但这是行不通的。 Any suggestions on how to set the title?
关于如何设置标题的任何建议?
UPDATE 更新
Ignore this I've been an idiot 忽略这个我是白痴
If you are creating a navigation bar yourself, you can change title by doing. 如果您自己创建导航栏,则可以这样做来更改标题。 navigationBar.topItem.title = "My Title"
navigationBar.topItem.title =“我的标题”
You can try this in your view did load function. 您可以在视图加载功能中尝试此操作。
self.navigationItem.title = "YourTitle" self.navigationItem.title =“您的标题”
You need to be doing something like this in the view controller where you need the title to be set. 您需要在需要设置标题的视图控制器中执行类似的操作。
override func viewDidLoad() {
super.viewDidLoad()
self.title = "some title"}
Wow I've just realised I've been a huge idiot. 哇,我刚刚意识到自己一直是个白痴。 The text was showing all along, it was just the same colour as the navigation bar >.<
文本一直显示,与导航栏>。<的颜色相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.