【问题标题】:i have error: no visible interface for 'UIAlertController'我有错误:“UIAlertController”没有可见界面
【发布时间】:2016-06-09 13:57:43
【问题描述】:

我是 Xcode(7.3) 和 ios(9.3) 的新手。我尝试了一个示例项目来显示警报消息,但出现如下错误:

“'UIAlertController' 没有可见界面声明'show'。Belo 我附上了代码。

//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 的文档中,您是否看到 show 的方法?

标签: ios objective-c cocoa-touch uikit uialertcontroller


【解决方案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];

【讨论】:

  • 我试过这个选项,现在错误没有出现,但警报没有显示。
【解决方案2】:

当您创建UIAlertController 时,您必须编写以下代码:

[self presentViewController:alert animated:YES completion:nil];

而不是

 [alert show];

有关UIAlertController的更多详细信息,请阅读:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/

【讨论】:

    【解决方案3】:

    你做错了。 show 仅适用于 UIAlertVIew,但不适用于 UIAlertAction

    UIALertAction 是添加到UIAlertController 的操作

    【讨论】:

      猜你喜欢
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多