pop回上上个页面导航栏显示错误问题记录

若想实现从一个页面pop回上上页面有两种方法:

1.使用popToViewController(对应视图控制器,animated:true),这种方法目前没发现坑,推荐使用

open func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?// Pops view controllers until the one specified is on top. Returns the popped controllers.

2.使用setViewControllers(堆栈中视图控制器数组,animated:true)

这个方法就是手动设置当前导航栏中视图控制器数组,既把需要移除的视图控制器从该数组中移除。

在使用这个方法是会有个很奇葩的坑,如果你使用的是系统导航栏,animated必须设置为true,否则在返回到上上个页面时,导航栏显示仍然是移除的那个控制器的导航栏。还有这种情况切记别使用self.navigationController.viewControllers.remove(at:self.navigationController.viewControllers.count - 2),

该方法同样会出现上述问题,原因暂时不清楚,待俺有时间搞搞清楚

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.

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

推荐阅读更多精彩内容