设置 UINavigationbar 的标题不起作用 [英] Setting title of UINavigationbar not working
问题描述
我浏览了一些在线教程,但没有任何效果.
I've looked through a few online tutorials, but nothing is working.
这是我的 viewController 的代码:
That's the code of my viewController:
import UIKit
class ViewController: UINavigationController {
let textView = UITextView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// tried this
self.navigationItem.title = "AAA"
// and this
self.title = "AAA"
// and finally this
self.parent?.title = "AAA"
}
}
我不明白为什么这不起作用(我以前没有使用过导航栏)
I don't understand why this isn't working (I haven't used a navigation bar before)
我没有更改 main.storyboard 中的任何内容.
I didn't change anything in the main.storyboard.
感谢您的回答.
推荐答案
首先在你的故事板中选择你的视图控制器,然后
First of all in your storyboard select your view controller and then
编辑器 -> 嵌入 -> 导航控制器
Editor -> Embed In -> Navigation Controller
然后在你的 ViewController
类中添加
then in your ViewController
class add
self.title = "AAA"
在您的 viewDidLoad
方法中,您的代码将如下所示:
in your viewDidLoad
method and your code will look like:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "AAA"
}
}
您需要将 UINavigationController
替换为 UIViewController
这篇关于设置 UINavigationbar 的标题不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!