Created
March 11, 2015 03:36
-
-
Save carlflor/b7c50801fa21a62c58f9 to your computer and use it in GitHub Desktop.
AlertView for Swift (iOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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