navigationController?.setViewControllers
在override func viewDidAppear(
中延迟工作,在其他情况下,它可以正常工作。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print(self.navigationController?.children)
print(self.navigationController?.viewControllers)
var array = self.navigationController?.children
array!.insert(ViewController(), at: array!.count - 1)
navigationController?.setViewControllers(array!, animated: false)
print(self.navigationController?.viewControllers)
}
它打印:
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.TwoViewController: 0x7f9a1b40e320>])
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.TwoViewController: 0x7f9a1b40e320>])
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.TwoViewController: 0x7f9a1b40e320>])
在其他情况下,它可以正常工作。就像单击按钮一样。
@IBAction func back(_ sender: Any) {
print(self.navigationController?.children)
print(self.navigationController?.viewControllers)
var array = self.navigationController?.children
array!.insert(ViewController(), at: array!.count - 1)
navigationController?.setViewControllers(array!, animated: false)
print(self.navigationController?.viewControllers)
}
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.ViewController: 0x7f9a1b520dc0>, <One.TwoViewController: 0x7f9a1b40e320>])
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.ViewController: 0x7f9a1b520dc0>, <One.TwoViewController: 0x7f9a1b40e320>])
Optional([<One.ViewController: 0x7f9a1b4021e0>, <One.ViewController: 0x7f9a1b520dc0>, <One.ViewController: 0x7f9a1b40cd10>, <One.TwoViewController: 0x7f9a1b40e320>])
它按预期工作。
这两种方法一个接一个地工作。
我认为navigationController?.setViewControllers
在override func viewDidAppear(
中工作,有点延迟。
什么是机制?