I'm practicing with a basic example of alerts, it's two ViewControllers, each one has a button to go to the next or return, and another button to show an Alert
I added a Simple Alert in the ViewControler1 and it works fine, but if I add a Simple Alert in the ViewControler2 it does not work and shows the following error:
2018-09-12 16: 23: 43.107112-0500 proyect1 [74831: 1130476] Warning: Attempt to present on whose view is not in the window hierarchy!
Code viewController1:
import UIKit
class ViewController1: UIViewController {
@IBAction func btnAlerta1 (_ sender: UIButton) {
let alert = UIAlertController (style: .alert, title: "Verify your data", message: "Enter your email and password correctly")
alert.addAction (title: "Ok", color: .black, style: .default) {action in}
alert.show ()
}
override func viewDidLoad () {
super.viewDidLoad ()
}
}
Code viewController2:
import UIKit
class ViewController1: UIViewController {
@IBAction func btnAlerta2 (_ sender: UIButton) {
let alert = UIAlertController (style: .alert, title: "Verify your data", message: "Enter your email and password correctly")
alert.addAction (title: "Ok", color: .black, style: .default) {action in}
alert.show ()
}
override func viewDidLoad () {
super.viewDidLoad ()
}
}
And if I go back to the ViewController1 and wish to invoke the Simple Alert that worked before, now it does not work and it presents the same error!
could you help me?