这是我的功能,我链接到按钮 . 它没有推送到另一个ViewController . 它应该按以下方式工作:用户单击按钮,按钮创建警报,警报停留在当前ViewController中或推送到不同的现有ViewController . 不知道它为什么不起作用 - 提醒节目并没有任何反应 . 标识符已设置且正确 .
let alert = UIAlertController(title: "Warning", message: "Aborting adding a routine scheme. Proceed?", preferredStyle: .alert)
alert.addAction(.init(title: "No", style: .cancel, handler: nil))
alert.addAction(.init(title: "Yes", style: .default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
// push to another VC
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "WorkoutViewController") as! WorkoutViewController
self.navigationController?.pushViewController(vc, animated: true)
}))
self.present(alert, animated: true, completion: nil)
1 回答
您当前的ViewController未嵌入
UINavigationController
中,因此该行不执行任何操作...因为
navigationController
是nil
如果你想只提出ViewController使用它