我有两页:
登录页面和注册页面:
对于登录页面,我使用以下内容获取信息并将失败或成功响应传递给用户:
- (void)login:(UIButton *)sender
{
[self.appDel.api loginWithEmail:self.email.text
password:self.password.text
completionHandler:^(id response, NSError *error) {
if (error) {
NSLog(@"ERROR: %@", error);
} else {
if ([[response objectForKey:Status] isEqualToString:Success]) {
self.currentUser = [response objectForKey:kResponseUser];
self.currentUserProfile = [response objectForKey:Profile];
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
} else {
NSLog(@"FAIL: %@", response);
[[[UIAlertView alloc] initWithTitle:@"Login Failed"
message:[response description]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}
}];
}
将此用于登录页面,如果用户没有完成两个必需的 texfields 或其中一个填充另一个空并按登录,他将收到失败消息。
但是,在注册的情况下,当文本字段为空并且我们单击注册时程序会崩溃。我应该如何改变这个:
-(void)signUp:(UIButton *)sender
{
[self.api signup:self.Email.text
password:self.Password.text
confirmationPassword:self.ConfirmPassword.text
firstName:self.FirstName.text
completionHandler:^(id response, NSError *error) {
if (error) {
NSLog(@"ERROR: %@", error);
} else {
if ([[response objectForKey:Status] isEqualToString:Success]) {
self.appDel.theNewUser = [response objectForKey:User];
self.appDel.theNewUserProfile = [response objectForKey:Profile];
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
} else {
NSLog(@"FAIL: %@", response);
[[[UIAlertView alloc] initWithTitle:@"SignUp Failed"
message:[response description]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}
}];
}