swift - Display an UIAlertView when app launches -


i'm trying add uialertview or controller when app first loads. currently, have code in viewdidload method.

let welcomealert = uialertcontroller(title: "hola", message: "this test.", preferredstyle: uialertcontrollerstyle.alert) welcomealert.addaction(uialertaction(title: "ok.", style: uialertactionstyle.default, handler: nil))  self.presentviewcontroller(welcomealert, animated: true, completion: nil) 

why won't alert view display? used same code inside of ibaction button, , works expected.

you should displaying alert in viewdidappear: function. present subview or view controller, parent view controller has in view hierarchy.

the viewdidappear function "notifies view controller view added view hierarchy."

* documentation

so, code this:

class myviewcontroller: uiviewcontroller {      override func viewdidappear(animated: bool){         super.viewdidappear(animated)          let welcomealert = uialertcontroller(title: "hola", message: "this test.", preferredstyle: uialertcontrollerstyle.alert)         welcomealert.addaction(uialertaction(title: "ok.", style: uialertactionstyle.default, handler: nil))         self.presentviewcontroller(welcomealert, animated: true, completion: nil)     }  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -