Is it possible to add UIAlert view inside UIAlertAction ?
Because when I tried to add UIAlert view inside UIAlertAction, it says
"Warning: Attempt to present on whose view is not in the window hierarchy!"
Here's my code.
let myAlert = UIAlertController(title: "Title", message: "title here", preferredStyle: UIAlertControllerStyle.alert)
let okaction = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler:
{
action in
let myViewController:ViewController = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let navigationController = UINavigationController.init(rootViewController: myViewController)
appDelegate.window?.rootViewController = navigationController
appDelegate.window?.makeKeyAndVisible()
if (statement here == 1) {
let myAlert = UIAlertController(title: "Title", message: "title", preferredStyle: UIAlertControllerStyle.alert)
myAlert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil))
self.present(myAlert, animated: true, completion: nil)
return
}
}
)
myAlert.addAction(okaction)
self.present(myAlert, animated: true, completion: nil)