alertview和alertviewcontroller的关系

来源:互联网 发布:linux 10秒后关机 编辑:程序博客网 时间:2024/05/16 11:53

在alertview在ios7.0之后就苹果不提倡用,随后就出现了AlertViewController。

本来也是不知道的,但直到公司的大哥跟我说之后,才知道AlertViewController。

首先先来谈谈,Alertview一般是用于警告提示,初始化方法为此

- (instancetype)initWithTitle:(NSString *)title message:(NSString*)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;

这个方法通过设置一个title,message,delegate,一些按钮的标题创建警告框,代码提示如下
UIAlertview *alert = [【UIAlertview alloc】initwithtitle:@"提示" message:@"这是一个提示框" delegate:self cancelbuttontitle:@“确定” otherbuttontitle:@"确定",nil];

【alert show】;
这样就显现出来啦

大体说挺好用的,但可惜呀在ios9.0 不能用了,而且我也不知道它的按钮添加方法怎么写,无法实现真正的高度自定义

所alertcontroller应运而生

代码如下:UIalertcontroller *alert = 【uialertcontroller alertcontrollerwithtitle:title message:message preferredstyle:uialertcontrllerstylealert】;
 
  UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {        NSLog(@"The \"Okay/Cancel\" alert's cancel action occured.");    }];        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {        NSLog(@"The \"Okay/Cancel\" alert's other action occured.");    }];        // Add the actions.    [alertController addAction:cancelAction];    [alertController addAction:otherAction];        [self presentViewController:alertController animated:YES completion:nil];}
就是自定义一个controller在里面按钮啦,在按钮的block方法里添加方法
再写方法,add到alert controller里,present显示出来就行了
额大概就学了这些,一般够用了

0 0
原创粉丝点击