iOS8之后UIAlertView被弃用 UIAlertController成功上位
来源:互联网 发布:软件开发部门ios 编辑:程序博客网 时间:2024/05/24 00:10
如图所示当你UIAlert时 UIAlertView被划了一道红线 说明oc已经弃用了UIAlertView 随之而来的是UIAlertController
那么UIAlertController怎么用呢 会不会很麻烦
别急 看代码
我现在需要一个弹出框 然后选择图片的来源 是从相册获取还是拍照
代码 点击已经设置好的icon 弹框
#pragma mark --更改icon--- (void)changeIconImage{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择图片来源" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *photography = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self photography]; }]; UIAlertAction *photoSelect = [UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self photoSelect]; }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]; [alert addAction:photography]; [alert addAction:photoSelect]; [alert addAction:cancel]; [self presentViewController:alert animated:YES completion:nil]; // UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"选择图片来源" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选取", @"拍照", nil];// // [as showInView:self.view]; }
#pragma mark --photography拍照--- (void)photography{ UIImagePickerController *ipc = [[UIImagePickerController alloc] init]; ipc.navigationBar.backgroundColor = [UIColor redColor]; //判断设备是否支持这种sourcetype if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ ipc.sourceType = UIImagePickerControllerSourceTypeCamera; } ipc.delegate = self; //是否允许编辑 ipc.allowsEditing = YES; [self presentViewController:ipc animated:YES completion:nil]; }- (void)photoSelect{ UIImagePickerController *ipc = [[UIImagePickerController alloc] init]; ipc.navigationBar.backgroundColor = [UIColor redColor]; //判断设备是否支持这种sourcetype if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){ ipc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } ipc.delegate = self; //是否允许编辑 ipc.allowsEditing = YES; [self presentViewController:ipc animated:YES completion:nil];}
#pragma mark---ImagePickerControllerDelegate---- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; iconImageView.image = image; [picker dismissViewControllerAnimated:NO completion:nil];}
这三段代码连起来问题就解决了 不过亲 要记得加上 UIImagePickerControllerDelegate,UINavigationControllerDelegate 这两个
下面解决问题的图片 测试 图片成功替换 没任何问题
0 0
- iOS8之后UIAlertView被弃用 UIAlertController成功上位
- ios8之后的UIAlertController
- iOS8之后UIAlertController
- iOS8.0之后的UIAlertController
- ios8之后的UIAlertController详解
- iOS8 --UIAlertView变成了UIAlertController
- iOS8 UIAlertController 创建UIAlertView以及UIActionSheet
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet)
- iOS8 UIAlertView 和 UIActionSheet 的新用法 UIAlertController详解
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- IOS8 UIAlertController
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- codeforces 189A. Cut Ribbon
- POJ3254-Corn Fields(状压DP)
- Python 报错IndentationError: unindent does not match any outer indentation level
- java实现快速排序
- jstl标签的用法(一)
- iOS8之后UIAlertView被弃用 UIAlertController成功上位
- js 窗口操作
- HDU 1561(树形dp)
- eclipse启动项目非常慢
- poj 2455 Secret Milking Machine (网络流)
- 找连续数 HDU5247
- leetcode Construct Binary Tree from Inorder and Postorder Traversal
- redis基本命令
- android适配