Ios Swift-推送警报操作以显示新的ViewController
当按钮处于警报状态时,如何显示或链接到新的ViewController 这是我的密码Ios Swift-推送警报操作以显示新的ViewController,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,当按钮处于警报状态时,如何显示或链接到新的ViewController 这是我的密码 let alert = UIAlertController(title: validateQRObj.responseDescription, message: validateQRObj.productName, preferredStyle: .alert) let action = UIAlertAction(title: "OK", style: .default) { (action) ->
let alert = UIAlertController(title: validateQRObj.responseDescription, message: validateQRObj.productName, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default) { (action) -> Void in
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ProductDetialViewController")
self.present(viewController!, animated: true, completion: nil)
}
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
控制从视图控制器1(黄点)拖动到视图控制器2上的任何位置,然后单击该段。显示属性检查器,并在序列图像板序列标识符名称下显示标识符VC2 如果这是你一直在寻找的答案,别忘了回答
func alert(){
let alertController = UIAlertController(title: "Open View Controller. ", message: "Press Ok to open View Controller number 2.", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in
//The (withIdentifier: "VC2") is the Storyboard Segue identifier.
self.performSegue(withIdentifier: "VC2", sender: self)
})
alertController.addAction(ok)
self.present(alertController, animated: true, completion: nil)
}
对我来说,它不起作用。我提出:
func alert(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let twop = storyboard.instantiateViewController(withIdentifier: "Accueil") as! Accueil
let alertController = UIAlertController(title: "Open new View !", message: "Clic to ok", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in
self.navigationController?.show(twop, sender: self)
})
alertController.addAction(ok)
self.present(alertController, animated: true, completion: nil)
}
现在它开始工作了 你发布的代码有什么问题?