我有一个BOOL loginStatus
要在登录流程中使用的。
代码
- (IBAction)login:(id)sender {
if ([self credentialsValidated]) {
[self performSegueWithIdentifier:@"showLogin" sender:self];
}else {
NSLog(@"not valid");
}
}
- (BOOL)credentialsValidated {
[[API sharedInstance] loginCommand:[NSMutableDictionary dictionaryWithObjectsAndKeys:_txtLogin.text,@"email",_txtPass.text,@"pwd", nil] onCompletion:^(NSDictionary *json){
//completion
if(![json objectForKey:@"error"]){
if([[json valueForKeyPath:@"data.status"]intValue] == 200){
//Create user object
NSLog(@"tot hier");
loginstatus = YES;
}else{
//show validation
NSString *message = [NSString stringWithFormat:@"%@",[json valueForKeyPath:@"data.text"]];
[[[UIAlertView alloc]initWithTitle:@"Fout" message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]show];
_txtLogin.text = @"";
_txtPass.text = @"";
loginstatus = NO;
}
}else {
NSLog(@"Cannot connect to the server");
}
}];
if(loginstatus){
NSLog(@"true");
}else{
NSLog(@"false");
}
return loginstatus;
}
我的问题是我BOOL
的没有立即设置。在正确设置布尔值之前,我总是需要按两次登录按钮。
有任何想法吗?