In the following piece of code, loginString is 0 when an incorrect username password is entered and is 206112814开发者_开发知识库3657912001 when a correct user name password is entered. However no matter what I do, I always get the pop up.
What am I missing?
//loginString is a 0 or a 2061128143657912001
if ([loginString intValue]>0) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:userName.text forKey:@"userNameKey"];
[defaults setObject:password.text forKey:@"passwordKey"];
[defaults synchronize];
[self dismissModalViewControllerAnimated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Validation Error" message:@"Unable to validate Login/Password combination" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
Try throwing in
NSLog(@"loginString = %@",loginString);
NSLog(@"loginString = %d",[loginString intValue]);
before the if
statement to see if things are really what you think they are.
That done, see what happens if you reverse the if
statement by
if ([loginString intValue] == 0) {
...
} else {
...
}
Or maybe even check [loginString isEqualToString:@"0"]
.
精彩评论