我查看了几个在线教程,但没有任何工作。
这是我的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"
}
}
我不明白为什么这不起作用(我以前没用过导航栏)
我没有更改main.storyboard中的任何内容。
谢谢你的回答。
首先在你的故事板中选择你的视图控制器然后
编辑器 - >嵌入 - >导航控制器
然后在你的ViewController
班加
self.title = "AAA"
在您的viewDidLoad
方法中,您的代码将如下所示:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "AAA"
}
}
你需要用UINavigationController
替换UIViewController