按下 uiAlert 按钮后以编程方式推送到新的 viewController

programmatically push to a new viewController after pressing uiAlert button

我想知道是否可以在按下 UiAlertController 中的按钮后推送到新的 ViewController

我的代码看起来像

 @objc func handleAcceptRequest() {
    let user = self.user
    let username = user?.name

    let alert = UIAlertController(title: "Are you Sure? ",message:" Would you like to accept \(username!) to complete your job?", preferredStyle: UIAlertController.Style.alert)

    let cancelButton = UIAlertAction(title: "Cancel", style: .default, handler: {(_ action: UIAlertAction) -> Void in
           print("you pressed cancel button")
       })

    let continueButton = UIAlertAction(title: "Continue", style: .default, handler: {(_ action: UIAlertAction) -> Void in

        let vc = viewController()
        let navController = UINavigationController(rootViewController: vc)

           print("you pressed Continue")

       })



    continueButton.setValue(GREEN_Theme, forKey: "titleTextColor")
    cancelButton.setValue(UIColor.red, forKey: "titleTextColor")
    alert.addAction(cancelButton)
    alert.addAction(continueButton)
    self.window?.rootViewController?.present(alert, animated: true, completion: nil)

  }

如果按下“继续”按钮,我只想显示 VC,但如果我调用当前

// self.present(navController, animated: true, completion: nil)

在 continueButton 内部,我收到错误 Use of unresolved identifier 'present'

可以这样推送一个新的VC吗?

这不对

// self.present(navController, animated: true, completion: nil)

应该是:

self.window?.rootViewController?. present(navController, animated: true, completion: nil)