Reputation: 7484
I have an extended UITextField (added a NSString property, inputType to it) to take in user input. when the user tap's the text field, i use a picker for the user to select the input. i also need to allow the user to clear the text box so i thought i could use
tillageTextField.clearButtonMode = UITextFieldViewModeAlways;
to clear the text field.
the issue is when you tap the X to clear the text box, it also fires my picker. i use:
-(BOOL) textFieldShouldBeginEditing:(MyTextField *) textField
{
//other code
else if ([textField.inputType isEqualToString:@"tillageMethod"])
{
self.customArray = [NSArray arrayWithObjects:@"No Till", @"Strip Till", @"Full Till", nil];
self.tempTextField = textField;
[self showPicker];
return NO;
}
//other code
}
to show the picker.
is there a way for me to tell if the user tapped the clear button and not show the picker?
Upvotes: 1
Views: 554
Reputation: 6064
You could also implement textFieldShouldClear:
and set a flag on your class (e.g. doNotShowPickerOnNextCallback
)
- (BOOL)textFieldShouldClear:(UITextField *)textField {
if ([textField.inputType isEqualToString:@"tillageMethod"]) {
if (![self pickerIsShowing]) {
self.doNotShowPickerOnNextCallback = YES;
}
}
return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//other code
else if ([textField.inputType isEqualToString:@"tillageMethod"]) {
if (self.doNotShowPickerOnNextCallback) {
self.doNotShowPickerOnNextCallback = NO;
return NO;
}
self.customArray = [NSArray arrayWithObjects:@"No Till", @"Strip Till", @"Full Till", nil];
self.tempTextField = textField;
[self showPicker];
return NO;
}
}
Upvotes: 1