我正在尝试制作我的第一个iOS应用,教程要求我使用uialertView。Xcode告诉我,这是不推荐使用的,我应该使用UialertController。我用uialertController替换了UialertView的实例,并且仍遇到问题:它说:"没有可见的@interface'uialertController'声明selector'initwithTitle:messagewithTitle:message:Message:dacturebuttontitle:cancelbuttontitle:otherbuttontitles:其他buttontitles:'''''''''''''''''我将感谢任何帮助。我的代码如下:
//
// ViewController.m
// cv
//
// Created by Frank Michael Tocci on 6/17/16.
// Copyright © 2016 Frank Tocci. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIAlertController * alert = [[UIAlertController alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
[alert show];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
uialertController的接口与uialertView不同。您必须使用仅包含标题,消息和首选样式的其他构造函数。
然后,您可以在定义后将操作添加到UialertController。单击"超级链接",该链接将带您到Apple的文档,在那里他们还提供了如何使用UialertController的示例。
uialertController不是uialertView
初始化并显示它的方式不同。以下是:
// Init the alert
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleAlert];
// Setup the action for the alert
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
// Add the defaultAction to the alert (this will add an action button with title "OK" to the alert)
[alert addAction:defaultAction];
// Display it
[self presentViewController:alert animated:YES completion:nil];
如果要为iOS 8部署应用程序,则只需将部署目标更改为iOS 8之后,您就不会发现使用AlertView
的任何折旧。 AlertView
在iOS 9及以上折旧,但在iOS 9以下仍然可以正常工作。