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
- Both UserID & UserPass are empty—>If statement works correctly.
- UserID is NOT empty & UserPass is empty —> not working. It just skipped my if statement even though second condition is true.
- UserID is empty & UserPass is NOT empty —>If statement works correctly.
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
try use : if ([UserID.text length] > 0]) {