隐含的功能声明'如果'在C99无效?

时间:2014-11-09 21:35:51

标签: objective-c

我试图为我的应用程序创建一个注册页面,当我发出'if'语句时,我收到了C99错误。我正在使用xCode 5.1.1,我正在使用解析SDK和框架工作。我不确定我做错了什么,但如果这是一个非常明显的错误我道歉。 :

- (IBAction)continueAction:(id)sender {
    [_usernameField resignFirstResponder];
    [_emailField resignFirstResponder];
    [_passwordField resignFirstResponder];
    [_retypeField resignFirstResponder];
    [self checkFieldsComplete];
}

- (void) checkFieldsComplete {
    If ([_usernameField.text isEqualToString:@""] || [_emailField.text isEqualToString:@""] || [_passwordField.text isEqualToString:@""] || [_retypeField.text isEqualToString:@""]); { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Woaaahhhh, hold on there" message:@"You must complete all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
     {
        [self checkPasswordsMatch];
    }

}

- (void) checkPasswordsMatch {
    if (![_passwordField.text isEqualToString:_retypeField.text]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Woaaahhhh" message:@"Passwords don't match" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    else {
        [self registerNewUser];
    }
}

1 个答案:

答案 0 :(得分:1)

问题在于这一行:

If ([_usernameField.text isEqualToString:@""] || [_emailField.text isEqualToString:@""] || [_passwordField.text isEqualToString:@""] || [_retypeField.text isEqualToString:@""]); { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Woaaahhhh, hold on there" message:@"You must complete all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

If重命名为if。 C关键字和标识符区分大小写。另外,在if语句后删除分号。如果if-statement为false,如果希望执行第二个块,则还需要插入else。总的来说,它应该是这样的:

if ([_usernameField.text isEqualToString:@""] || [_emailField.text isEqualToString:@""] || [_passwordField.text isEqualToString:@""] || [_retypeField.text isEqualToString:@""])
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Woaaahhhh, hold on there" message:@"You must complete all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}
else
{
    [self checkPasswordsMatch];
}