Skip to content

Instantly share code, notes, and snippets.

@carlflor
Created March 11, 2015 03:36
Show Gist options
  • Save carlflor/b7c50801fa21a62c58f9 to your computer and use it in GitHub Desktop.
Save carlflor/b7c50801fa21a62c58f9 to your computer and use it in GitHub Desktop.
AlertView for Swift (iOS)
if self.reviews.count == 0 {
var alert = UIAlertController(title: "Whoops...", message: "No reviews yet!", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Okay",
style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in
self.navigationController?.popViewControllerAnimated(true)
return //force return since popViewControllerAnimated(true) returns a ViewController instead of void
}))
//alternative action
/*alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
switch action.style{
case .Default:
self.navigationController?.popViewControllerAnimated(true)
case .Cancel:
println("cancel")
case .Destructive:
println("destructive")
}
}))*/
self.presentViewController(alert, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment