Machado
Machado

Reputation: 14489

Why is my UIAlertController not being fired?

I want to display a UIAlertController whenever user opens the application.

This is how I'm creating and trying to show it:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //simple alert dialog
        let alert=UIAlertController(title: "Alert 1", message: "One is awesome", preferredStyle: UIAlertControllerStyle.Alert);
        //show it
        showViewController(alert, sender: self);

    }
}

Why is it not being displayed?

Upvotes: 0

Views: 123

Answers (2)

Bacon
Bacon

Reputation: 812

It will work if you'd use: presentViewController(alert, animated: true, completion: nil)

As @matt stated, it’s better to present your alertViewController in ViewDidAppear instead of ViewDidLoad, because than the presenting viewController is in the interface.

Upvotes: 4

matt
matt

Reputation: 535139

Too soon. In viewDidLoad, your view is not even in the interface yet! There is nothing to show from.

Upvotes: 2

Related Questions