0
let alert = UIAlertController(title: "Title", message: "message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Title", style: UIAlertActionStyle.default, handler: { action in self.alertFunc() }))

If I build this the alert view doesn't appear. What have I missed?

P.S. I know there are some similar question but to find out what they have and I have missed is hard

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
E. Tess
  • 17
  • 2

2 Answers2

3

You have to present the alerte view on your view.

self.present(alert, animated: true, completion: nil)
l30c0d35
  • 777
  • 1
  • 8
  • 32
2

You need to present it too on your current context:

self.present(alert, animated: true, completion: nil)

Add that row at the end of your alert declaration:

let alert = UIAlertController(title: "Title", message: "message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Title", style: UIAlertActionStyle.default, handler: { action in 
    self.alertFunc() 
}))
self.present(alert, animated: true, completion: nil)
Rashwan L
  • 38,237
  • 7
  • 103
  • 107