Can't add an Alert Action to UIAlertController (Swift) -


i'm trying add ok button ui alert cannot add using alertcontroller.addaction

what do in case?

thanks in advance!!

if error == nil {                 let alert: uialertcontroller = uialertcontroller(title: "account created", message: "please confirm email", preferredstyle: .alert)                  let okbutton = uialertaction(title: "ok", style: .default) { action -> void in                     self.performseguewithidentifier("tomain", sender: self)                      alertcontroller.addaction(okbutton)                   self.presentviewcontroller(alert, animated: true, completion: nil)                  }                  } else {                  println("\(error)")             } 

  1. alert instead of alertcontroller
  2. alert.addaction should outside of okbutton action.

change code :

if error == nil {     let alert: uialertcontroller = uialertcontroller(title: "account created", message: "please confirm email", preferredstyle: .alert)      let okbutton = uialertaction(title: "ok", style: .default) { action -> void in         self.performseguewithidentifier("tomain", sender: self)      }     alert.addaction(okbutton)      self.presentviewcontroller(alert, animated: true, completion: nil)  } else {              println("\(error)")         } 

Comments