Reputation: 2799
I have a data entry app which I have developed primarily with iOS7 in focus but it will support ios 6. I noticed that when I am trying to check if a UITextField
is empty when I try to validate a form in iOS6 it will tell me that it is not empty if there is a placeholder text there. In iOS 7 I don't have this problem.
Does anyone have any efficient solution for this except for matching every UITextField's
content with its placeholdet text for all the UITextFields
in the whole app?
EDIT:
If the validation is the issue, here is my validation code. Very simply I iterate through an array with the mandatory UITextFields
and check if there is any input in them.
-(void)checkIfComplete{
BOOL complete = YES;
for(int i = 0; i < self.mandatoryFields.count; i++){
UITextField *tempTextField = self.mandatoryFields[i];
if([tempTextField.text isEqual: @""]){
complete = NO;
}
}
if(complete){
self.btnSave.enabled = YES;
}else{
self.btnSave.enabled = NO;
}
}
EDIT 2:
Okey this is very weird. When I load the ViewController
with the UITextFields
the validation is wrong (it says the form is complete even though it is not). But if I enter a UITextField
, write something and then delete what I just wrote the validation is correct (it says the form is incomplete when it is). I am setting my placeholders from the Storyboard if that makes any difference.
Thank you
Upvotes: 0
Views: 254
Reputation: 1677
Try this
-(void)checkIfComplete{
BOOL complete = YES;
for(int i = 0; i < self.mandatoryFields.count; i++){
UITextField *tempTextField = self.mandatoryFields[i];
if(tempTextField.text.length == 0){
complete = NO;
break;
}
}
self.btnSave.enabled = complete;
}
Upvotes: 5