如何在AppDelegate didBecomeActive中更改视图?

时间:2019-02-27 11:28:08

标签: ios swift xcode

   func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.



    let navVC = self.window?.rootViewController as! UINavigationController

    if navVC.topViewController is ViewQuestionViewController {
       // Here I want the the view to be QuizTableViewController
      // so that navVC.topViewController is QuizTableViewController

    }

该应用程序激活后(if navVC.topViewController is ViewQuestionViewController),这变为事实。我希望将if navVC.topViewController用作QuizTableViewController,以便在应用程序激活后,如果不是QuizTableViewController,则它应该变成QuizTableViewController

1 个答案:

答案 0 :(得分:0)

您可以尝试

let qui =  UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "QuizTableID") as! QuizTableViewController
var vcs = navVC.viewControllers 
vcs.dropLast() 
vcs.append(qui)
navVC.viewControllers = vcs

如果您需要在导航中使用男性测验唯一的vc

navVC.viewControllers = [qui]