简体   繁体   English

使用未声明的标识符“警报”

[英]Use of undeclared identifier 'alert'

I am getting an error that says: Use of undeclared identifier 'alert' 我收到一条错误消息: Use of undeclared identifier 'alert'

NSAlert *alert = [NSAlert alertWithMessageText: @"Why ? "
                                         defaultButton:@"OK"
                                       ];

Can someone tell me why am i getting this error ? 有人可以告诉我为什么会出现这个错误吗?

Updated: 更新:

在此处输入图片说明

I think you mean 我想你是说

UIAlertView *alert

Not

NSAlert *alert // "NSAlert" does not exist in the Cocoa API.

Your clue from the compiler is that it says the type NSAlert is undefined. 您从编译器得到的线索是它说类型NSAlert是未定义的。 If the type is undefined, then you can get another error about the variable itself being undefined, which is why it says alert is undefined. 如果类型是未定义的,那么您会得到另一个有关变量本身未定义的错误的信息,这就是为什么它说alert是未定义的。

For OS 8 & above use UIAlertController & for below use UIAlertview. 对于OS 8及更高版本,请使用UIAlertController;对于OS 8及更高版本,请使用UIAlertview。

if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
{
    alertView = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter CVV2 code." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    txt_CVV2CodeResult.text = @"";
}
else
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning:" message:@"Please enter CVV2 code." preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *OKAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                                         style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction *action)
                                       {

                                       }];

    [alertController addAction:OKAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

For iOS, you need UIAlertView, not NSAlert. 对于iOS,您需要UIAlertView,而不是NSAlert。 NSAlert is a Mac OS X class. NSAlert是Mac OS X类别。

Refer 参考

Where is NSAlert.h in the iOS SDK? iOS SDK中的NSAlert.h在哪里?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM