我是Xcode(7.3)和ios(9.3)的新手。我尝试了一个示例项目来显示警报消息,但我收到以下错误:
"'UIAlertController'没有可见的界面声明'显示'。贝洛我附上了代码。
//ViewController.m//
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert show];
//AppDelegate.h//
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end.
请帮帮我。
试试:
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
当你创建UIAlertController
时,你必须编写下面的代码:
[self presentViewController:alert animated:YES completion:nil];
而不是
[alert show];
有关UIAlertController
的更多详细信息,请阅读:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/
你做错了。 节目仅适用于UIAlertVIew
,但不适用于UIAlertAction
。
UIALertAction
是添加到UIAlertController