8.0之前两个控件分别创建
8.0之后两个控件统一由UIAlertController管理
例:
UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示消息" message:@"账号密码有误" preferredStyle:UIAlertControllerStyleAlert];
其中preferredStyle的定义是:
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = 0,
UIAlertControllerStyleAlert
} NS_ENUM_AVAILABLE_IOS(8_0);
通过改变preferredStyle来决定使用alertView还是actionSheet
定义alertAction并添加到alert中
UIAlertAction * defaultAction = [UIAlertAction actionWithTitle:@"请重新输入" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{
//在block中写点击之后要做的事情
((ViewController*)vc).usernameTextField.text = @"";
((ViewController*)vc).passwordTextField.text = @"";
}];
[alert addAction:defaultAction];
如果不是在VC文件中而是在请求数据类似的其他文件中触发了alertView,在对原VC进行操作时,要将原VC作为参数传过来,并在头文件导入原VC,并将传过来的参数强转,再进行操作。