<bdo id='z0l4I'></bdo><ul id='z0l4I'></ul>

    <small id='z0l4I'></small><noframes id='z0l4I'>

      <legend id='z0l4I'><style id='z0l4I'><dir id='z0l4I'><q id='z0l4I'></q></dir></style></legend>

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

      <tfoot id='z0l4I'></tfoot>
      1. Swift – 在 App Delegate 中实例化没有故事板的导航控制器

        时间:2023-05-17

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

                • <bdo id='1GnoE'></bdo><ul id='1GnoE'></ul>
                    <tbody id='1GnoE'></tbody>

                  <small id='1GnoE'></small><noframes id='1GnoE'>

                  本文介绍了Swift – 在 App Delegate 中实例化没有故事板的导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在重建一个没有情节提要的应用程序,其中我遇到最大问题的部分是以编程方式导航视图到视图.很少有不使用故事板的东西写出来,因此很难找到答案.

                  I'm rebuilding an app without storyboards and the part of it that I'm having the most trouble with is navigating view-to-view programatically. Few things are written out there which don't use storyboards, so finding an answer for this has been tough.

                  我的问题很简单.我有我的 ViewController 和我的 SecondViewController,我想从前者推送到后者.

                  My problem is pretty simple. I have my ViewController and my SecondViewController and I want to push from the former to the latter.

                  AppDelegate中:

                  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
                      // Override point for customization after application launch.
                  
                      window = UIWindow(frame: UIScreen.mainScreen().bounds)
                      window?.backgroundColor = UIColor.whiteColor()
                      window?.rootViewController = ViewController()
                      window?.makeKeyAndVisible()
                  
                      return true
                  }
                  

                  然后在ViewController.swift中:

                  class ViewController: UIViewController, AVAudioPlayerDelegate, UITextFieldDelegate {
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                  
                          startFinishButton.setTitle("Begin", forState: .Normal)
                          startFinishButton.addTarget(self, action: "moveToSecondViewController", forControlEvents: .TouchUpInside)
                          view.addSubview <*> startFinishButton
                      }
                  
                      func moveToSecondViewController(sender: UIButton) {
                          let vc = SecondViewController()
                          println(self.navigationController) // returns nil
                          self.navigationController?.pushViewController(vc, animated: true)
                      }
                  }
                  

                  打印 self.navigationController 返回 nil.我试过这样做:

                  Printing self.navigationController returns nil. I've tried doing:

                  var navController = UINavigationController()ViewController 类被创建(但在 ViewDidLoad 之外,就在类声明下方)并使用 完成推送时navController var 但没有奏效.

                  var navController = UINavigationController() when the ViewController class is created (but outside of ViewDidLoad, right under the class declaration) and done the push using the navController var but that hasn't worked.

                  我在想也许解决方案是在 App Delegate 中创建一个导航控制器,整个应用程序都会使用它,我猜它是一个全局变量?

                  I'm thinking maybe the solution is to create a navigation controller in App Delegate that the whole app would use, I guess as a global variable?

                  我希望这篇文章可以为许多刚接触 Swift 并希望从他们的应用程序中删除故事板的人提供帮助.

                  My hope is that this post can serve many others who are new to Swift and want to remove storyboards from their app.

                  感谢您的浏览和帮助.

                  推荐答案

                  在 Swift 3 中

                  将此代码放在 AppDelegate 类的 didFinishLaunchingWithOptions 方法中.

                  Place this code inside didFinishLaunchingWithOptions method in AppDelegate class.

                  window = UIWindow(frame: UIScreen.main.bounds)
                  let mainController = MainViewController() as UIViewController
                  let navigationController = UINavigationController(rootViewController: mainController)
                  navigationController.navigationBar.isTranslucent = false
                  self.window?.rootViewController = navigationController
                  self.window?.makeKeyAndVisible()
                  

                  这篇关于Swift – 在 App Delegate 中实例化没有故事板的导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在Xcode导航栏控制器的标题下添加字幕 下一篇:如何在 iOS 8 中使用 UISearchController,其中 UISearchBar 在我的导航栏中并且有范围

                  相关文章

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

                    <small id='agE7U'></small><noframes id='agE7U'>

                    1. <tfoot id='agE7U'></tfoot>