Reputation: 32143
There's a tiny 🅧 button inside editable text UITextField
s that clears the text. I want to listen for this to, say, reset the text "$0.00"
instead of ""
, to close the dialog automatically, etc. How can I listen for this button to be pressed?
Upvotes: 2
Views: 297
Reputation: 385970
In your text field's delegate, implement textFieldShouldClear:
. From the documentation:
The text field calls this method in response to the user pressing the built-in clear button.
It sounds like you want to write this:
- (BOOL)textFieldShouldClear:(UITextField *)textField {
textField.text = @"";
[self textFieldDidClear:textField];
return NO;
}
- (void)textFieldDidClear {
// To be overridden by subclasses.
}
Upvotes: 3
Reputation: 119031
Don't, instead set your cell as the delegate and when the text is updated to be an empty string you can deny the edit and directly set your text.
Upvotes: 0