Reputation: 653
I have this simple if statement that check UItextfields if empty or not like this:
if([UserID.text isEqualToString:@""] || [UserPass.text isEqualToString:@""]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Fields can not be empty." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
}
Here is problem, first time when I enter the view has these UItextfields. I test like this
Now the interesting part is here,if I dont exit the view during the test. I check UserID is NOT empty & UserPass is empty again(test#2 above), then the of statement work correctly. If I exit the view during the test, then if statement act weird again.
Can anyone help me to point out what did I do wrong here? Thank you very much
Upvotes: 2
Views: 214
Reputation: 180867
Sounds like UserPass (or UserPass.text) is not set to what you think it is; it may be set set to nil, which would make isEqualToString on it to always return false. If you hadn't made it work occasionally, I'd say there's a disconnected outlet.
Upvotes: 1
Reputation: 11690
Try NSLog("bool value: %d", [UserID.text isEqualToString:@""] || [UserPass.text isEqualToString:@""]); before evaluating the IF-statement to see the Boolean value.
Upvotes: 0
Reputation: 1484
Wired. Did you check whether your UserID and UserPass are defined as IBOutlet and connected in the IB?
Upvotes: 0