Reputation: 241
It is my function I linked to button. It doesn't push to another ViewController. It should work in following way : User clicks button, button creates alert, alert stays in current ViewController or pushes to different existing ViewController. No idea why it is not working - alert shows and nothing happens. Identifier is set and correct.
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)
Upvotes: 1
Views: 845
Reputation: 11210
Your current ViewController isn't embed in UINavigationController
so this line does nothing
self.navigationController?.pushViewController(vc, animated: true)
... because navigationController
is nil
If you want to just present ViewController use this
self.present(vc, animated: true, completion: nil)
Upvotes: 4