解散初始ViewController

时间:2017-06-02 18:13:47

标签: ios swift3

我正在使用swift 3开发一款应用。我在我的应用程序的第一次启动时启动了一个像视图控制器的教程,并使用一个按钮关闭它。但即使单击关闭按钮,初始视图控制器也不会被解雇。我知道这个问题听起来很熟悉,但我无法得到正确的解决方案。

以下是AppDelegate的代码

import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
func application(_ application: 
UIApplication,didFinishLaunchingWithOptions launchOptions: [ 
UIApplicationLaunchOptionsKey: Any]?) -> Bool
{

let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")

            if launchedBefore {
                print("This is not the first Launch")
            } else
               {
                print("First Launch, setting UserDefaults")
                UserDefaults.standard.set(true, forKey: "launchedBefore")
                self.window = UIWindow(frame: UIScreen.main.bounds)

                let storyBoard = UIStoryboard(name: "Main", bundle: nil)

                let initiaView = storyBoard.instantiateViewController(withIdentifier: "FirstLaunchViewController")
                self.window?.rootViewController = initiaView
                self.window?.makeKeyAndVisible()


            }
    return true
}

这是来自initialViewController的代码

  class FirstLaunchViewController:UIViewController
  {

     override func viewDidLoad() {
     }

    @IBAction func doneButtonTapped(_ sender: Any) 
    {
      _ = navigationController?.popViewController(animated:true)
    }
 }

2 个答案:

答案 0 :(得分:0)

尝试将视图控制器设置为取消初始视图控制器后要显示的窗口的根视图控制器。从窗口根视图控制器

呈现初始视图控制器

答案 1 :(得分:0)

试试这个

let rootViewController = self.window?.rootViewController // this is your initial viewcontroller set initial viewcontroller in storyboard
let initiaView = storyBoard.instantiateViewController(withIdentifier: "FirstLaunchViewController")
 rootViewController.pushViewController(initiaView, animated: true)