Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何返回到rootviewcontroller_Ios_Swift_Cocoa Touch_Segue - Fatal编程技术网

Ios 如何返回到rootviewcontroller

Ios 如何返回到rootviewcontroller,ios,swift,cocoa-touch,segue,Ios,Swift,Cocoa Touch,Segue,我有四个视图控制器A、B、C和D 我从A到B再到C再到D let newViewContoller: B = self.storyboard?.instantiateViewControllerWithIdentifier("B") as! B self.presentViewController(newViewContoller, animated: true, completion:nil) 从D回到A 我正在使用下面的 self.view.window!.rootViewCo

我有四个视图控制器A、B、C和D

我从A到B再到C再到D

 let newViewContoller: B = self.storyboard?.instantiateViewControllerWithIdentifier("B") as! B    
 self.presentViewController(newViewContoller, animated: true, completion:nil)
从D回到A

我正在使用下面的

self.view.window!.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
我面临的问题是,, 正在调用viewController B和viewController C的
ViewDid


我不知道为什么会这样?返回初始视图控制器的正确方法是什么?视图控制器A、B、C和D位于堆栈数据结构中,实现后进先出。这意味着要通过解除ViewController来访问ViewController A,它将按以下顺序弹出ViewController D、C、B。在这种情况下,从堆栈中弹出的ViewController C和B将在一瞬间成为最顶层的ViewController,这将触发ViewWillAspect()和viewWillDissapear()函数。苹果文档:

对堆栈中较低的视图控制器调用此方法将取消其直接子视图控制器以及堆栈中该子视图控制器之上的所有视图控制器


相反,如果您有一个导航控制器,并且不想让C和B出现,您应该做的是从当前显示的viewController(D)中弹出popToRootViewController(),它将弹出当前视图,然后解除锁定C和B,然后显示a。

据我所知,一次关闭4个控制器是不可能的,但有一个棘手的办法--

创建一个从ViewcontrollerD到Viewcontrollera的序列,称之为
ForceSegue
,然后您应该在a控制器上有一些东西来执行此操作,如果是操作,请粘贴以下内容。。 目标-c

[self performSegueWithIdentifier:@"ForceSegue" sender:self];
Swift 3

performSegue(withIdentifier: "ForceSegue", sender: self)
只是一种狡猾的方式,
希望这有帮助

搜索展开段检查此问题的解决方案您是否使用pushController演示B、C和D控制器?在这种情况下,您可以使用from D navigationController?.popToRootViewController(动画:true,完成:nil)“我从A到B到C到D”???这是什么意思?你如何“从……到”?您正在使用导航控制器吗?塔巴控制器?你在使用presentViewController()吗?@DonMag我在使用presentViewController