0

我制作了一个 ViewController,每次应用程序进入前台时都会显示。这是因为我希望用户每次应用程序进入前台时都进行身份验证(就像银行应用程序一样)。我以这种方式制作了此功能:

  func applicationDidEnterBackground(_ application: UIApplication) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "localauth")
        self.window!.rootViewController = controller;
        self.window!.makeKeyAndVisible();
  }

自我窗口!是 AppDelegate.swift 的一个属性。我自己添加了这个。我不确定这是要走的路:

var window: UIWindow?

AppDelegate 中的这个函数在应用进入后台时将当前的 ViewController 切换到 Auth ViewController。因此,当应用再次进入前台时,会显示“localAuth”视图控制器。

当用户通过身份验证时,处理身份验证的 ViewController 会显示下一个 ViewController:

self.performSegue(withIdentifier: "localAuthed", sender: self);

LocalAuth ViewController 通过名为 localAuthed 的 segue 与 storyboard 中的下一个 ViewController 连接。下一个 ViewController 是 NavigationController,因此它显示嵌入在该 NavigationController 中的第一个 ViewController。

现在这就是发生的事情。显示了右侧嵌入的 ViewController,但缺少操作栏的标题。稍等片刻,标题就出现了。

我呈现 ViewController 的方式是否正确?

4

0 回答 0