I am trying to show a UIAlertController as my view loads. I know that's impossible during viewDidLoad() or viewWillAppear() because the view is not in the hierarchy at during the execution of those functions. However, if the view is added before viewDidAppear(), then it should be possible to show my UIAlertController during the call of that function.
Therefore, I tried this:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
var AlertShow = false
print(Configuration)
if !AlreadyLoad {
if Configuration.count == 0 {
AlertShow = true
print("First lunch")
let Alert = UIAlertController(title: "Premier lancement", message: "C'est la première fois que l'application est lancée. Cette dernière va télécharger tous les articles.\nVeuillez patienter.", preferredStyle: .Alert)
let OkAction = UIAlertAction(title: "Ok", style: .Default) { (action) in }
Alert.addAction(OkAction)
self.presentViewController(Alert, animated: true, completion: {
AlertShow = false
})
}
}
But my alert is only visible after the execution of viewDidAppear().
I would like show this alert at the beginning.
I am using Swift 2, Xcode 7, and the iOS 9 SDK.