<i id='xTQf8'><tr id='xTQf8'><dt id='xTQf8'><q id='xTQf8'><span id='xTQf8'><b id='xTQf8'><form id='xTQf8'><ins id='xTQf8'></ins><ul id='xTQf8'></ul><sub id='xTQf8'></sub></form><legend id='xTQf8'></legend><bdo id='xTQf8'><pre id='xTQf8'><center id='xTQf8'></center></pre></bdo></b><th id='xTQf8'></th></span></q></dt></tr></i><div id='xTQf8'><tfoot id='xTQf8'></tfoot><dl id='xTQf8'><fieldset id='xTQf8'></fieldset></dl></div>

      1. <small id='xTQf8'></small><noframes id='xTQf8'>

        <tfoot id='xTQf8'></tfoot>
      2. <legend id='xTQf8'><style id='xTQf8'><dir id='xTQf8'><q id='xTQf8'></q></dir></style></legend>
          <bdo id='xTQf8'></bdo><ul id='xTQf8'></ul>

      3. Swift - 来自 appDelegate 的 pushViewController,rootViewControll

        Swift - pushViewController from appDelegate, rootViewController.navigationController is nil(Swift - 来自 appDelegate 的 pushViewController,rootViewController.navigationController 为 nil)
            <bdo id='5M84L'></bdo><ul id='5M84L'></ul>
            <legend id='5M84L'><style id='5M84L'><dir id='5M84L'><q id='5M84L'></q></dir></style></legend>
            • <small id='5M84L'></small><noframes id='5M84L'>

              <tfoot id='5M84L'></tfoot>
              <i id='5M84L'><tr id='5M84L'><dt id='5M84L'><q id='5M84L'><span id='5M84L'><b id='5M84L'><form id='5M84L'><ins id='5M84L'></ins><ul id='5M84L'></ul><sub id='5M84L'></sub></form><legend id='5M84L'></legend><bdo id='5M84L'><pre id='5M84L'><center id='5M84L'></center></pre></bdo></b><th id='5M84L'></th></span></q></dt></tr></i><div id='5M84L'><tfoot id='5M84L'></tfoot><dl id='5M84L'><fieldset id='5M84L'></fieldset></dl></div>
                  <tbody id='5M84L'></tbody>

                1. 本文介绍了Swift - 来自 appDelegate 的 pushViewController,rootViewController.navigationController 为 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在遵循一些指南时遇到问题,特别是http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/

                  Having a problem following a few guides, specifically http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/

                  我正在设置 url 方案,从另一个应用程序启动该应用程序运行良好,但传入主机或 url 并不能正常工作.我正在为所有视图布局使用故事板和界面构建器.

                  I'm setting the url scheme and it's working well to launch the app from another app, but passing in the host or url are not working as it seems it should. I'm using storyboards and interface builder for all the view layouts.

                  指南在 appDelegate 中显示了这个 openURL:

                  The guide shows this openURL in appDelegate:

                  -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
                      if([[url host] isEqualToString:@"page"]){
                          if([[url path] isEqualToString:@"/page1"]){
                              [self.mainController pushViewController:[[Page1ViewController alloc] init] animated:YES];
                          }
                      return YES;
                      }
                  }
                  

                  这是我从其他几个来源快速简化的版本,即在 Swift 中从 AppDelegate 获取 ViewController 实例 我跳过目前 url 主机的条件以删除问题中的潜在其他变量.

                  Here is my version simplified and in swift from a few other sources, ie Get Instance Of ViewController From AppDelegate In Swift I'm skipping the conditional for the url host at the moment to remove potential other variables in the problem.

                  func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
                      var rootViewController = self.window!.rootViewController
                      let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                      var profileViewController = mainStoryboard.instantiateViewControllerWithIdentifier("profile") as ProfileViewController
                  
                      rootViewController.navigationController.popToViewController(profileViewController, animated: true)
                  
                      return true
                  
                  }
                  

                  swift 版本导致崩溃:致命错误:在展开可选值时意外发现 nil

                  The swift version causes a crash: fatal error: unexpectedly found nil while unwrapping an Optional value

                  好像rootViewController还没有navigationController?

                  It seems that rootViewController doesn't have a navigationController yet?

                  推荐答案

                  在我的例子中,rootViewController 似乎实际上是 UINavigationController 类型,所以在声明中强制转换允许我直接在其上调用 pushToViewController.

                  It seems that rootViewController actually is of type UINavigationController in my case, so casting it on declaration allowed me to call pushToViewController directly on it.

                  func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
                      let rootViewController = self.window!.rootViewController as! UINavigationController
                      let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
                      let profileViewController = mainStoryboard.instantiateViewController(withIdentifier: "InstructionVC") as! InstructionVC
                      rootViewController.pushViewController(profileViewController, animated: true)
                      return true
                  
                  }
                  

                  这篇关于Swift - 来自 appDelegate 的 pushViewController,rootViewController.navigationController 为 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                  How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                  How to get the previous viewcontroller that pushed my current view(如何获取推送我当前视图的上一个视图控制器)
                  The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)
                  View being blocked by UITransitionView after being presented(呈现后被 UITransitionView 阻止的视图)
                  Show UITabBar when UIViewController pushed(推送 UIViewController 时显示 UITabBar)
                    <bdo id='pX4Yw'></bdo><ul id='pX4Yw'></ul>

                          <tbody id='pX4Yw'></tbody>
                      • <tfoot id='pX4Yw'></tfoot>

                          <legend id='pX4Yw'><style id='pX4Yw'><dir id='pX4Yw'><q id='pX4Yw'></q></dir></style></legend>
                          <i id='pX4Yw'><tr id='pX4Yw'><dt id='pX4Yw'><q id='pX4Yw'><span id='pX4Yw'><b id='pX4Yw'><form id='pX4Yw'><ins id='pX4Yw'></ins><ul id='pX4Yw'></ul><sub id='pX4Yw'></sub></form><legend id='pX4Yw'></legend><bdo id='pX4Yw'><pre id='pX4Yw'><center id='pX4Yw'></center></pre></bdo></b><th id='pX4Yw'></th></span></q></dt></tr></i><div id='pX4Yw'><tfoot id='pX4Yw'></tfoot><dl id='pX4Yw'><fieldset id='pX4Yw'></fieldset></dl></div>
                          1. <small id='pX4Yw'></small><noframes id='pX4Yw'>