In iPhone, I have a view which has a UITextField
. When I tap on the clear button of UITextField
\'s the keyboard dismissed instead of clearing the text
Just clear the field, resignFirstResponder
(if you want to hide keyboard) and return NO
/false
Note: set Attributes inspector property of UITextField
Clear Button -> Appears while editing
so it will display the clear button while editing in the text field.
// Objective-C
-(BOOL)textFieldShouldClear:(UITextField *)textField
{
textField.text = @"";
[textField resignFirstResponder];
return NO;
}
// Swift
func textFieldShouldClear(textField: UITextField) -> Bool {
textField.text = ""
textField.resignFirstResponder()
return false
}