以编程方式推送到新的视图控制器后按 uiAlert 按钮



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

。我的代码看起来像

@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, complete: nil(

在继续按钮内,我收到错误使用未解析的标识符"存在">

是否可以以这种方式推送新VC?

这是不对

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

它应该是:

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

最新更新