我是Xcode(7.3)和ios(9.3)的新手。我尝试了一个示例项目来显示警告信息,但我得到的错误如下:
“没有'UIAlertController的可见界面'声明'show'。我在附上代码。
//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.
请帮帮我。
答案 0 :(得分:1)
尝试改为:
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];
答案 1 :(得分:1)
在创建UIAlertController
时,您必须编写以下代码:
[self presentViewController:alert animated:YES completion:nil];
而不是
[alert show];
有关UIAlertController
的详细信息,请参阅:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/
答案 2 :(得分:0)
你做错了。 show仅适用于UIAlertVIew
,但不适用于UIAlertAction
。
UIALertAction
是添加到UIAlertController