我有一个 我可以使用导航堆栈中上一个视图控制器的标题创建一个自定义后退按钮,作为一种解决方法,但是我很好奇为什么会首先出现这种情况,并且可能会更简单地解决。UIViewController
A嵌入在UINavigationViewController
中,该A推动另一个视图控制器B执行某些操作。给定A的UIViewController.title
设置为“ VC A”,则在显示B时,后退按钮的标题将为“ class ViewControllerA: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "VC A"
}
func doSomething() {
// Instantiate ViewControllerB
navigationController?.pushViewController(viewControllerB, animated: true)
}
}
class ViewControllerB: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "VC B" // Works as expected
}
func doSomething() {
title = "VC B" // Causes the back button title to change to Back from VC A
}
}