Last active
January 31, 2018 18:37
-
-
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.
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
// | |
// 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