Hi I am using to following code to keep 2 UIButtons disabled until there is data in four UITextFields
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (([brand.text length] >0) && ([qty.text length] >0) && ([size.text length] >0) && ([price.text length] >0)) {
[calcOneButton setEnabled:YES];
[calcTwoButton setEnabled:YES];
}
if (([brand.text length] ==0) || ([qty.text length] ==0) || ([size.text length] ==0) || ([price.text length] ==0)){
[calcOneButton setEnabled:NO];
[calcTwoButton setEnabled:NO];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
int ebtl = [brand.text length];
int eqtl = [qty.text length];
int estl = [size.text length];
int eptl = [price.text length];
NSLog(@"ebtl = %d eqtl = %d estl = %d eptl = %d",ebtl, eqtl, estl, eptl);
if (([brand.text length] ==0) || ([qty.text length] ==0) || ([size.text length] ==0) || ([price.text length] ==0)){
[calcOneButton setEnabled:NO];
[calcTwoButton setEnabled:NO];
}
if (([brand.text length] >0) && ([qty.text length] >0) && ([size.text length] >0) && ([price.text length] >0)) {
[calcOneButton setEnabled:YES];
[calcTwoButton setEnabled:YES];
}
}
My problem is that textFieldDidEndEditing isn’t called until the user taps away from the textField. this creates the need to tap the screen then the button is there a way to avoid this, so the button will be enabled immediately?
The button will become active only when the user taps away from textField. If you are using the normal keyboard which pops up, use the DONE button on the keyboard to get rid of the keyboard, and then write an IBAction when the keyboard resigns itself, and then enable your buttons.
or use an IBAction:
The buttons must get active only when ALL textFields are filled right ? You can do this.
Comment out both the functions you have written above. Use the IBAction and whenever you press the DONE and resign the keyboard , check all textFields for their status. Using an if-else block, make your buttons appear when all textFields are done.