如果变量x高于1000,我想弹出警报视图。在Xcode for iPhone中 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];
}
答案 0 :(得分: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
}
}