IOS9.0中Alert的创建

来源:互联网 发布:魔术笔软件 编辑:程序博客网 时间:2024/06/05 07:56

在IOS9.0中,摒弃了IOS中的UIAlertView控件。所以以往的方法不能使用;下面是在IOS9.0中创建Alert控件的Source Code:

UIAlertController *alt = [UIAlertController alertControllerWithTitle:@"提示"                                                                     message:@"输入错误"preferredStyle:UIAlertControllerStyleActionSheet];        [alt addAction:[UIAlertAction actionWithTitle:@"取消"                                                style:(UIAlertActionStyleCancel)                                              handler:^(UIAlertAction * _Nonnull action) {                                              }]];                [self presentViewController:alt animated:YES completion:nil];



其中preferredStyle是一个枚举类型(只包含两种):UIAlertControllerStyleActionSheet、UIAlertControllerStyleAlert;

一个是从底部弹出,一个是中间显示;

handler、completion:是点击取消按钮后需要执行的代码,可以设置为nil;

如果还要添加其他的按钮:

UIAlertAction *addNo = [UIAlertAction actionWithTitle:@"其他"                                                        style:UIAlertActionStyleDefault                                                      handler:nil];        [alt addAction:addNo];




0 0