class ViewController: UIViewController, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
navigationController!.delegate = self
}
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
print("showViewController")
}
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
print("sss")
}
func update() {
let vc = SecondViewController()
navigationController!.pushViewController(vc, animated: true)
}
}
這是我的演示的第一控制器,並在控制檯:UINavigationControllerDelegate的didShowViewController方法被調用兩次
sss
showViewController
showViewController
的「didShowViewController」被稱爲兩次。 我不確定發生了什麼
----------------- some test ------------------ ----
我在控制器的這些方法中添加一些日誌:的loadView,viewDidLoad中,viewWillAppear中,viewDidAppear,和這些日誌的順序是:
loadView
viewDidLoad
viewWillAppear
will:<NaviDemo.ViewController: 0x7fe8c9533050>
<NaviDemo.ViewController: 0x7fe8c9533050>
viewDidAppear
<NaviDemo.ViewController: 0x7fe8c9533050>
謝謝你,我試過你的建議, 控制檯 ,它打印相同的實例兩次 –
爲什麼被稱爲兩次的方法? @James Zaghini –