我想让一个警报视图弹出,如果一个变量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];
}
这就是我自己问题的答案:
- (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
}
}