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 performSegue将下一个视图控制器推入不需要的视图层次_Ios_Swift_Uiviewcontroller_Uinavigationcontroller_Uistoryboard - Fatal编程技术网

Ios performSegue将下一个视图控制器推入不需要的视图层次

Ios performSegue将下一个视图控制器推入不需要的视图层次,ios,swift,uiviewcontroller,uinavigationcontroller,uistoryboard,Ios,Swift,Uiviewcontroller,Uinavigationcontroller,Uistoryboard,我正在构建一个基于导航的应用程序,在这个应用程序中,您可以使用底部选项卡进行导航,每个选项卡都有自己的导航堆栈。 大部分零件按预期工作,但有一个特定选项卡的行为出乎意料 正在发生的是: 在浏览了几个视图控制器之后,比如[A][B][C]和[D],下一个控制器[E]突然从导航堆栈中消失。 发生这种情况时,视图看起来像是以模式显示的,导航堆栈看起来像这样 (lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy] &l

我正在构建一个基于导航的应用程序,在这个应用程序中,您可以使用底部选项卡进行导航,每个选项卡都有自己的导航堆栈。 大部分零件按预期工作,但有一个特定选项卡的行为出乎意料

正在发生的是:

在浏览了几个视图控制器之后,比如[A][B][C]和[D],下一个控制器[E]突然从导航堆栈中消失。 发生这种情况时,视图看起来像是以模式显示的,导航堆栈看起来像这样

(lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy]

<MyApp.CRTabBarController 0x112026800>, state: disappeared, view: <UILayoutContainerView 0x111e1fa00> not in the window
   | <UINavigationController 0x112027a00>, state: disappeared, view: <UILayoutContainerView 0x111e23f50> not in the window
   |    | <MyApp.X1_ViewController 0x111d12490>, state: disappeared, view: <UIView 0x111e32d70> not in the window
   |    |    | <MyApp.InsideX1_ViewController 0x112096200>, state: disappeared, view: <UIView 0x111e35d90> not in the window
   | <UINavigationController 0x11200aa00>, state: disappeared, view: (view not loaded)
   |    | <MyApp.X2_ViewController 0x111d22360>, state: disappeared, view: (view not loaded)
   | <UINavigationController 0x11205a200>, state: disappeared, view: (view not loaded)
   |    | <MyApp.X3_Controller 0x11205a800>, state: disappeared, view: (view not loaded)
   | <UINavigationController 0x112059600>, state: disappeared, view: (view not loaded)
   |    | <MyApp.X4_ViewController 0x111e0cea0>, state: disappeared, view: (view not loaded)
   | <UINavigationController 0x112058e00>, state: disappeared, view: <UILayoutContainerView 0x111d50370> not in the window
   |    | <MyApp.A_ViewController 0x111d25f70>, state: disappeared, view: <UIView 0x116e0ad90> not in the window
   |    |    | <MyApp.PageViewController 0x112891400>, state: disappeared, view: <_UIPageViewControllerContentView 0x113feb0a0> not in the window
   |    |    |    | <MyApp.InnerPageViewController 0x111ee3bf0>, state: disappeared, view: <UIView 0x111e6e000> not in the window
   |    | <MyApp.B_ViewController 0x113ee8280>, state: disappeared, view: <UIView 0x116e37cf0> not in the window
   |    | <MyApp.C_Controller 0x118f06f10>, state: disappeared, view: <UIView 0x113ee46f0> not in the window
   |    | <MyApp.D_ViewController 0x116e5f580>, state: disappeared, view: <UIView 0x118f2fe70> not in the window
   + <E_ViewController 0x116ecff30>, state: appeared, view: <UIView 0x111ee43f0>, presented with: <_UIFullscreenPresentationController 0x116e13420>
self.performSegue(withIdentifier: "goto_E", sender: self)
我认为Segue的设置也很正常。它只是指定id并显示为样式。Segue从D_ViewController连接到E_ViewController,因此它可以被称为performSegue的标识符arg


有人有过这种经历吗?猜测可能的原因吗?

/p>//删除segue并实例化

extension UIViewController {

     class func instantiate(fromStoryboard name: String, id: String) -> Self? {
         return instantiateHelper(fromStoryboard: name, id: id)
     }

     private class func instantiateHelper<T>(fromStoryboard name: String, id: String) -> T? {
         let storyboard = UIStoryboard(name: name, bundle: nil)
         let controller = storyboard.instantiateViewController(withIdentifier: id) as? T
         return controller
     }
}

谢谢你的评论,但我已经自己解决了。 说起来很尴尬,但原因很傻,它在调用performSegue之前调用了popViewController

这个流行歌曲之所以出现,是因为我的观点结构发生了变化,很难注意到,因为它是在单独的地方写的

虽然这不是一个直接的答案,但是直接从故事板实例化的方法对于澄清这个问题很有用。谢谢,Pratyush

但完全出乎意料的是,在拉动segue之前弹出视图控制器会导致这种行为。
希望这能对其他人的问题有所启发。

为什么?删除segue并使用实例化的原因是什么?所有的事情都应该这样做,而segues却从来没有使用过吗?看起来这是一个很好的解决办法。关键是从故事板上抓取VC并将其直接推送到导航控制器,对吗?“让我试一试。”很多时候,赛格都不能正常工作。因此,最好是实例化。只有在某些设置不正确的情况下,segue才会正常工作。只要一切都正确编码,就不会有问题。实例化肯定不是更好,因为它否定了故事板的许多功能和WWDC对话的大部分。从D到E的顺序是否与链中的其他顺序相同,如B到C或C到D?是的,它们都是相同的。我通过点击序列进行视觉比较,除了标识符之外没有任何变化。它们以相同的方式从B_ViewController到C_ViewController,从C_ViewController到D_ViewController?我对所有这些转换使用PerformScheue,转换A到B,B到C和C到D都以相同的滑动效果执行。正如我在最初的帖子中所写,控制器a~D被卡在正确的导航堆栈中。
 guard let vc = ViewController.instantiate(fromStoryboard: "Main", id: "ViewController") else { return }
 self.navigationController?.pushViewController(vc, animated: true)