我想知道是否可以在按下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)
}
我仅想按Continue按钮,但如果我叫现在的话就显示VC
// self.present(navController,动画:true,完成:nil)
在continueButton内,出现错误,使用未解析的标识符'present'
是否可以通过这种方式推送newVC?
self.window?.rootViewController?. present(navController, animated: true, completion: nil)
这是因为在其中没有要显示viewController的navigationController。 viewController出现在navigationController上。