0

如果变量 x 高于 1000,我想让警报视图弹出。在 iPhone 的 Xcode 中,Xcode 给出错误:“if”前面的预期表达式

到目前为止,这是我的代码:

if (x>1000) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Title", nil)
                                message:NSLocalizedString(@"Message", nil)
                                delegate:nil
                                cancelButtonTitle:NSLocalizedString(@"OK", nil)
                                otherButtonTitles:nil];
    [alert show];
    [alert release];
}
4

1 回答 1

0

这就是我自己的问题的答案:

- (void)textFieldDidEndEditing:(UITextField *)textField {

float x = ([numberOfPeople.text floatValue]);

if (x>1000) {
    UIAlertView *objAlert = [[UIAlertView alloc] 
initWithTitle:@"Fehler" message:@"The entered Number should not be higher than 1000." 
delegate:nil 
cancelButtonTitle:nil 
otherButtonTitles:@"Close",nil];
    [objAlert show];

    textField.text=@""; // clears the text field
}

}

于 2013-01-17T09:37:18.590 回答