Created
June 20, 2016 20:07
-
-
Save olxios/6812fb9a47ef8c36c0bf2e27bb3b285d to your computer and use it in GitHub Desktop.
Testing UIAlertController: http://swiftiostutorials.com/using-uialertcontroller-instead-good-old-uialertview/
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
@IBAction func testAlert1() { | |
let controller = UIAlertController(title: "Error!", message: "Test error message", preferredStyle: .Alert) | |
let alertAction = UIAlertAction(title: "Dismiss", style: .Destructive) { (action) in | |
print("Dismiss button tapped!") | |
} | |
controller.addAction(alertAction) | |
presentViewController(controller, animated: true, completion: nil) | |
} |
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
@IBAction func testAlert2() { | |
let controller = UIAlertController(title: "Error!", message: "Test error message", preferredStyle: .Alert) | |
let alertAction = UIAlertAction(title: "Dismiss", style: .Destructive) { (action) in | |
print("Dismiss button tapped!") | |
} | |
controller.addAction(alertAction) | |
controller.addAction(UIAlertAction(title: "1", style: .Default, handler: nil)) | |
controller.addAction(UIAlertAction(title: "2", style: .Default, handler: nil)) | |
controller.addAction(UIAlertAction(title: "3", style: .Default, handler: nil)) | |
controller.addAction(UIAlertAction(title: "4", style: .Default, handler: nil)) | |
presentViewController(controller, animated: true, completion: nil) | |
} |
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
@IBAction func testMultipleCancels() { | |
let controller = UIAlertController(title: "Error!", message: "Test multiple cancels", preferredStyle: .Alert) | |
let firstCancelAction = UIAlertAction(title: "Cancel 1", style: .Cancel) { (action) in | |
print("Cancel 1 button tapped!") | |
} | |
controller.addAction(firstCancelAction) | |
let secondCancelAction = UIAlertAction(title: "Cancel 2", style: .Cancel) { (action) in | |
print("Cancel 2 button tapped!") | |
} | |
controller.addAction(secondCancelAction) // Exception! | |
presentViewController(controller, animated: true, completion: nil) | |
} |
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
@IBAction func testTextField() { | |
let controller = UIAlertController(title: "Error!", message: "Test error message", preferredStyle: .Alert) | |
let alertAction = UIAlertAction(title: "Dismiss", style: .Destructive) { (action) in | |
print("Dismiss button tapped!") | |
let text = controller.textFields?.first?.text | |
print("Textfield text \(text!)") | |
} | |
controller.addAction(alertAction) | |
controller.addTextFieldWithConfigurationHandler { (textField) in | |
textField.placeholder = "Test" | |
textField.textColor = UIColor.redColor() | |
} | |
presentViewController(controller, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment