UIAlertController的简单介绍

在Xcode的iOS8 SDK中,UIAlertView和UIActionSheet都被UIAlertController取代。官方库解释:“UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead.”、“UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead.”。说明了在iOS8+开发,UIALertView和UIActionSheet已经过时了,UIAlertController以一种模块化替换的方式来代替这两这两个控件的功能和作用。

UIAlertController的简单介绍_第1张图片
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"新建相册" message:@"请输入新建相册的名字"preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {
    }];
    
    [alert addAction:cancelAction];
    [alert addAction:otherAction];
    [alert addTextFieldWithConfigurationHandler:nil];
 
    [self presentViewController:alert animated:YES completion:nil];
UIAlertController的简单介绍_第2张图片
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"选择方式" message:@""preferredStyle:UIAlertControllerStyleActionSheet];
 
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {
    }];     
    UIAlertAction *photoLibraryAction = [UIAlertAction actionWithTitle:@"从相册读取" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {
    }];
    UIAlertAction *takePhotoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {
    }];
 
    [alert addAction:cancelAction];
    [alert addAction:takePhotoAction];
    [alert addAction:photoLibraryAction];
    
    [self presentViewController:alert animated:YES completion:nil];

你可能感兴趣的:(UIAlertController的简单介绍)