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 in the UITextField
. On an iPad it is working correctly. What can I do to fix this?
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
}
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