若想實現(xiàn)從一個頁面pop回上上頁面有兩種方法:
1.使用popToViewController(對應(yīng)視圖控制器,animated:true),這種方法目前沒發(fā)現(xiàn)坑,推薦使用
open func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?// Pops view controllers until the one specified is on top. Returns the popped controllers.
2.使用setViewControllers(堆棧中視圖控制器數(shù)組胀糜,animated:true)
這個方法就是手動設(shè)置當(dāng)前導(dǎo)航欄中視圖控制器數(shù)組,既把需要移除的視圖控制器從該數(shù)組中移除臊恋。
在使用這個方法是會有個很奇葩的坑,如果你使用的是系統(tǒng)導(dǎo)航欄墓捻,animated必須設(shè)置為true,否則在返回到上上個頁面時抖仅,導(dǎo)航欄顯示仍然是移除的那個控制器的導(dǎo)航欄。還有這種情況切記別使用self.navigationController.viewControllers.remove(at:self.navigationController.viewControllers.count - 2),
該方法同樣會出現(xiàn)上述問題,原因暫時不清楚撤卢,待俺有時間搞搞清楚
open func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.