Created
August 11, 2014 19:07
-
-
Save genedelisa/9bf44469c7f40772f5d1 to your computer and use it in GitHub Desktop.
UIAlertController in Swift
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
// ios8 and later | |
var alert = UIAlertController(title: "Hey!", | |
message: "How 'bout dat?", | |
preferredStyle: .Alert) | |
let textConfigClosure: ((UITextField!) -> Void)! = { text in | |
text.placeholder = "Type something here" | |
} | |
alert.addTextFieldWithConfigurationHandler(textConfigClosure) | |
alert.addTextFieldWithConfigurationHandler({textfield in | |
textfield.placeholder = "foo" | |
}) | |
alert.addAction(UIAlertAction(title: "Confirm", style: .Default, handler: {action in | |
println("confirm was tapped") | |
})) | |
let otherClosure: ((UIAlertAction!) -> Void)! = { action in | |
println("other was tapped") | |
let tf = alert.textFields[0] as UITextField | |
println(tf.text) | |
} | |
alert.addAction(UIAlertAction(title: "Other", style: .Default, handler: otherClosure)) | |
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