erstelle ich eine Demo, sie zu erklären:
Sie sehen, meine vc1
ist gelb-grau color
einbetten in einem navigation controller
, mein vc2
ist hellgrün color
einbetten in einem navigation controller
auch die zwei navigation controller
wird alles von einem tabbar controller
verwaltet.
In ViewController.swift
(es ist vc1
), wenn ich self.title
gesetzt:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "vc1's title"
}
}
In ViewController2.swift
(es ist vc2
):
import UIKit
class ViewController2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "vc2's title"
}
}
Das Ergebnis der tabbar title
und navigation title
alle Set:
Wenn ich gesetzt self.navigationController?.title
:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// self.title = "vc1's title"
self.navigationController?.title = "vc1's nav title"
}
}
Das Ergebnis wird tabbar title
gesetzt:
Wenn ich self.navigationItem.title
gesetzt:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// self.title = "vc1's title"
//self.navigationController?.title = "vc1's nav title"
self.navigationItem.title = "vc1's navItem title"
}
}
Das Ergebnis wird navigation title
gesetzt:
Haben Sie self.navigationController.navigationItem.title versuchen? – Kevin
Ich weiß, es funktioniert als dein Demo, ich möchte die Ursache dafür wissen, dann kann ich entscheiden, welches ich in meiner zukünftigen Entwicklung verwenden soll. – Kevin