【发布时间】:2019-02-13 06:44:24
【问题描述】:
我遇到了一个问题,当我“关闭并打开”一个应用程序时,同一个 ViewController 会出现两次。该应用程序的设置方式是,当用户“关闭和打开”应用程序时,它会将他们带到一个“PIN”视图控制器,在那里他们输入他们的 PIN 码。问题是当用户访问“PIN”视图控制器时,视图控制器会出现两次。我怎样才能使这种情况不会发生?另外,一旦用户输入“PIN”,我该如何让用户回到他们在“关闭然后打开”应用程序之前的最后一个页面?
删除应用程序中的代码以允许用户在“打开和关闭”应用程序时转到“PIN”视图控制器:
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
DispatchQueue.global(qos: .background).async {
print("This is run on the background queue")
DispatchQueue.main.async {
print("This is run on the main queue, after the previous code in outer block")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let yourVC = mainStoryboard.instantiateViewController(withIdentifier: "PINViewController") as! PINViewController
appDelegate.window?.rootViewController = yourVC
appDelegate.window?.makeKeyAndVisible()
}
}
}
【问题讨论】:
标签: ios swift uiviewcontroller appdelegate