Reputation: 14489
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
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
Reputation: 535139
Too soon. In viewDidLoad
, your view is not even in the interface yet! There is nothing to show
from.
Upvotes: 2