Last active
May 30, 2018 07:26
-
-
Save BalajiMalliswamy/75158d6292788bec2690d03310711957 to your computer and use it in GitHub Desktop.
Exploring UIAlertController in swift
This file contains hidden or 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
/** | |
Simple Alert with Text input | |
*/ | |
func showAlertWithTextField() { | |
let alertController = UIAlertController(title: "Add new tag", message: nil, preferredStyle: .alert) | |
let confirmAction = UIAlertAction(title: "Add", style: .default) { (_) in | |
if let txtField = alertController.textFields?.first, let text = txtField.text { | |
// operations | |
print("Text==>" + text) | |
} | |
} | |
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in } | |
alertController.addTextField { (textField) in | |
textField.placeholder = "Tag" | |
} | |
alertController.addAction(confirmAction) | |
alertController.addAction(cancelAction) | |
self.present(alertController, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment