Your First iOS App - Part 4: Alerts | Ray Wenderlich Videos

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

At 4:18 when you enter ( after present, I don’t get the same suggestions.

1 Like

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?

@robmn Do you still have issues with this?

@drw_sh Please check out this post when you get a chance:

I hope it helps!

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)
    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.

1 Like