假设我在堆栈中有四个VC:View1,View2,View3和View4。完成View4后,我想回到View2而不是弹出到View3。
我目前用来完成此任务的代码是:
let allViewControllers = self.navigationController?.viewControllers
for thisVC in allViewControllers!{
if thisVC.isKind(of: View2.self){
self.navigationController?.popToViewController(thisVC, animated: true)
}
}
我遇到的问题是我在最终登陆View2之前看到了View3的动画效果。换句话说,我按下调用上述代码的View4上的按钮,然后它弹出到View3,然后弹出到View2。有没有办法直接跳转到View2而不看到中间的View3?
如果它是相关的,这是我用来从View3推送View4的代码
let vc = self.storyboard!.instantiateViewController(withIdentifier: "View3") as! View3ViewController
self.navigationController?.pushViewController(vc, animated: true)
答案 0 :(得分:1)
您可以通过使用视图控制器的故事板标识符来实现此目的。
let mainStoryBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let view2 : UIViewController = mainStoryBoard.instantiateViewController(withIdentifier: "view_2_id") as UIViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = view2
self.window?.makeKeyAndVisible()