我浏览了一些在线教程,但没有任何效果。
那是我的 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 中的任何内容。
感谢您的回答。
最佳答案
首先在你的 Storyboard中选择你的 View Controller 然后
编辑器 -> 嵌入 -> 导航 Controller
然后在你的 ViewController
类中添加
self.title = "AAA"
在您的 viewDidLoad
方法中,您的代码将如下所示:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "AAA"
}
}
您需要将 UINavigationController
替换为 UIViewController
关于swift - UINavigationbar 的设置标题不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55631031/