有時候的需求是從rootController跳轉至頁面A再跳轉至頁面B, 然后從B返回時直接返回到rootController, 如果按鈕返回的話可以用
navigationController?.popToRootViewController(animated: true)
但是現(xiàn)在大部分人都習慣從屏幕左側滑動返回, 此時仍然會返回到頁面A.
解決辦法是在A進入B時, 把A從navigationController的contollers里移除.
let root = navigationController?.viewControllers.first!
navigationController?.setViewControllers([root!, B], animated: true)
這樣側滑返回時也是直接返回到rootController