Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ashfurrow/uialertcontroller-example
A demonstration of how to use Apple's hot new UIAlertController class
https://github.com/ashfurrow/uialertcontroller-example
Last synced: 2 months ago
JSON representation
A demonstration of how to use Apple's hot new UIAlertController class
- Host: GitHub
- URL: https://github.com/ashfurrow/uialertcontroller-example
- Owner: ashfurrow
- License: mit
- Created: 2014-09-07T15:54:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-07T17:30:43.000Z (over 10 years ago)
- Last Synced: 2024-05-09T20:02:13.586Z (8 months ago)
- Language: Swift
- Homepage: http://ashfurrow.com/blog/uialertviewcontroller-example
- Size: 137 KB
- Stars: 20
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UIAlertController-Example
=========================So Apple added this new [UIAlertViewController](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertController_class/) class in iOS 8. Cool, right? I mean, it came with next to no sample code despite replacing `UIAlertView` and `UIActionSheet`, which are now deprecated, so.
I had a hard time figuring out how to get the text field's text value. The only solution I found was to store the `UITextField` instance in a property of the view controller presenting it, which is a very ... Objective-C way of doing things. We can do better.
So I wrote a [blog post](http://ashfurrow.com/blog/uialertviewcontroller-example) exploring the API. Here's what I came up with.
```swift
let promptController = UIAlertController(title: "Type Something", message: nil, preferredStyle: .Alert)
let ok = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
println("\(alertViewControllerTextField?.text)")
})
let cancel = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in
}
promptController.addAction(ok)
promptController.addAction(cancel)
promptController.addTextFieldWithConfigurationHandler { (textField) -> Void in
alertViewControllerTextField = textField
}
presentViewController(promptController, animated: true, completion: nil)
```