Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Last active January 31, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlcollard/8e4c3793c8c4b24977d8ab251e336db3 to your computer and use it in GitHub Desktop.
Save mlcollard/8e4c3793c8c4b24977d8ab251e336db3 to your computer and use it in GitHub Desktop.
iOS: Make a text keyboard disappear. Used to show UIViewController as delegate for text field.
//
// Setup for UITextFieldDelegate
//
// Note: Comments with this label are to explain semantics of iOS
// Do not use comments like these in your projects
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
// email address entry
// Note: Must create text field in storyboard, and connect to this IBOutlet
@IBOutlet weak var emailText: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Note: All delegate methods for the emailText will go through this object
self.emailText.delegate = self
}
// Make the keyboard disappear once return is pressed
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.textField.resignFirstResponder()
// Note: implements default return key behavior
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment