[:en]Here are the procedures to hide keyboard by using 3 different methods:
import UIKit
// Add UITextFieldDelegate
class FreetrialformViewController: UIViewController , UITextFieldDelegate{
@IBOutlet weak var dateLabel: UIButton!
@IBOutlet weak var studentnamelabel: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
//Enable tapping feature
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap)
// Activate Keyboard delegate
self.studentnamelabel.delegate = self;
self.coursenamelabel.delegate = self;
}
// Call a function to hide keyboard
func checkpassword() {
self.studentnamelabel.resignFirstResponder()
}
//Tap anywhere to hide keyboard
func dismissKeyboard() {
view.endEditing(true)
}
// Hit return key to hide keyboard
func textFieldShouldReturn(textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
}
[:]
