iOS 侧滑返回到rootViewController

有时候的需求是从rootController跳转至页面A再跳转至页面B, 然后从B返回时直接返回到rootController, 如果按钮返回的话可以用

navigationController?.popToRootViewController(animated: true)

但是现在大部分人都习惯从屏幕左侧滑动返回, 此时仍然会返回到页面A.
解决办法是在A进入B时, 把A从navigationController的contollers里移除.

let root = navigationController?.viewControllers.first!
navigationController?.setViewControllers([root!, B], animated: true)

这样侧滑返回时也是直接返回到rootController

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容