How can I implement it in the new language of Apple:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView *view in self.view.subviews)
[view resignFirstResponder];
}
I have tried to do so. But the keyboard does not disappear:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
self.view.resignFirstResponder()
}
Causes the view (or one of its embedded text fields) to resign the first responder status.
An abstract interface for responding to and handling events.
In Objective-C:[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; This will resign the first responder (and dismiss the keyboard) every time, without you needing to send resignFirstResponder to the proper view. No matter what, this will dismiss the keyboard.
You could probably go with:
self.view.endEditing(true)
Try this
self.view.endEditing(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With