I've got 2 view controllers. The main one mainMenuViewController, and the secondary one ViewController.
The secondary view controller has an alert that is sometimes displayed, and when the user selects "Cancel", I want the mainMenuViewController to be displayed.
How can I achieve this with code?
So far I've got the following:
let refreshAlert = UIAlertController(title: "You Win!", message: "Do you want to play again?", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
self.restart()
}))
refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
print("Handle Cancel Logic here")
}))
presentViewController(refreshAlert, animated: true, completion: nil)
When the user clicks Cancel, I've temporarily printed the line print("Handle Cancel Logic here"), but I need the mainMenuViewController to become active.
I've tried creating a function to do this, but it won't work, can you suggest why?
@IBAction func quit(sender: UIBarButtonItem) {
let vc = mainMenuViewController()
self.presentViewController(vc, animated: true, completion: nil)
}
Any help appreciated!