權當自己記錄了, 不咋想好好寫文章了
只有在iPhoneX上有這個問題, 以前沒發現啊
導航的部分代碼
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if self.viewControllers.count > 0 {
viewController.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
返回部分的代碼
@IBAction func back(_ sender: Any) {
// 第一種有問題
self.navigationController?.popToRootViewController(animated: true)
// 第二種有問題
if let vcs = self.navigationController?.viewControllers {
for vc in vcs {
if vc.isKind(of: First2ViewController.self) {
self.navigationController?.popToViewController(vc, animated: true)
}
}
}
// 第三種可以
var vcs = self.navigationController?.viewControllers
vcs!.remove(at: vcs!.count-2)
self.navigationController?.viewControllers = vcs!
self.navigationController?.popViewController(animated: true)
}
原因:
在iPhoneX上直接返回到根視圖的時候,正常是出棧, 但是去了棧低。
結果到最后是navigationConroller的viewControllers里有兩個vc。
到底是不是iPhoneX的bug,我也不糾結了,問題搞定了。 但是這個有問題的返回是什么原理就有點好奇了, 自己不知道