Learn how to make the app display a popup alert when you tap a button.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5993-your-first-ios-app/lessons/4
Learn how to make the app display a popup alert when you tap a button.
Hello!
I have a common problem (google didn’t help me alas):
Warning: Attempt to present <UIAlertController: …> on <BullsEyes.ViewController: …> whose view is not in the window hierarchy!
What is strange is that when I did the “knock-knock” button, it worked but not “hit me!”.
Can you help me?
Sorry, no :c
Here’s the code:
@IBAction func showAlert() {
let message = "The value of the slider is now: \(currentValue)" let alert = UIAlertController(title: "Hello, World!", message: message, preferredStyle: .alert) let action = UIAlertAction(title: "OK", style: .default, handler: nil) alert.addAction(action) present(alert, animated: true, completion: nil) }
I’ve tried to change the order of the “present”-statement but alas…
For me the issue was that I’ve left print("Hello!")
from previous part. I have no idea why, but deleting it fixed everything.