Objective-C利用AFN上传头像、UIAlertController的使用
来源:互联网 发布:牛听听网络配置出错 6 编辑:程序博客网 时间:2024/06/06 05:21
iOS8推出了一个新的“controller”,主要是把类似之前的UIAlertView变成了UIAlertController,把UIAlertView和UIActionSheet二合一。
按钮响应方法弃用了代理而绑定使用了block方式,使可读性更强,不必在两个地方写代码了,但也需要注意循环引用的问题:__block typeof (self) weak_self = self;
向UIAlertController里面添加UIAlertAction的方式实现之前的UIActionSheet控件的功能,把[alert show]的方法改成了controller的presentViewController形式。这里借着上传头像的demo介绍一下这个新的提示框的用法。
AlertView:
NSString *tips = @"相机不可用"; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"无法使用相机" message:tips preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"取消"); }]; UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"确定"); }]; [alertController addAction:cancelAction]; [alertController addAction:otherAction]; [self presentViewController:alertController animated:YES completion:nil];
Actionsheet:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请选择图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}]; UIAlertAction* fromPhotoAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"从相册选择"); }]; UIAlertAction* fromCameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"相机"); }]; [alertController addAction:cancelAction]; [alertController addAction:fromCameraAction]; [alertController addAction:fromPhotoAction]; [self presentViewController:alertController animated:YES completion:nil];
此外上传头像访问相册和拍照的方法也很简单,UIImagePickerController很容易实现,但需要注意权限的问题。上传到服务器则直接调用AFN的post请求即可,具体代码可参考demo。
demo效果:
GitHub:https://github.com/FEverStar/UploadHeadImage
0 0
- Objective-C利用AFN上传头像、UIAlertController的使用
- 利用AFN上传文件
- 使用afn 上传图片
- objective-c - 基础篇 - UIAlertController提示框的调用
- Objective-C利用AFN实现图片下载,支持断点续传,显示下载进度
- 利用AFN进行多图片上传
- iOS- 利用AFNetworking(AFN) - 实现文件上传
- iOS- 利用AFNetworking(AFN) - 实现图片上传 -
- iOS利用AFNetworking(AFN) 实现图片上传
- iOS- 利用AFNetworking(AFN) - 实现图片上传
- iOS- 利用AFNetworking(AFN) - 实现图片上传
- iOS- 利用AFNetworking(AFN) - 实现图片上传
- iOS利用AFNetworking(AFN) 实现图片上传
- iOS利用AFNetworking(AFN) 实现图片上传
- 利用 AFN 上传相册或拍照图片
- ionic Camera插件的使用(头像上传)
- 使用AFN上传图片,显示上传进度
- 利用UIActionsheet完成上传头像
- 寻找android中的设计模式(一)
- SVProgressHUD控件使用
- 使用 t-SNE算法和JavaScript语言可视化Visualizing Top Tweeps with t-SNE, in Javascript
- 基于ZooKeeper的分布式Session实现
- VS2013常用快捷键
- Objective-C利用AFN上传头像、UIAlertController的使用
- 最详细的mac下Android studio配置gradle的路径
- Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义
- 矩阵快速幂模板
- rsyslog+loganalyzer系统日志分析系统(基础搭建)
- poj-1276 Cash Machine(多重背包)
- JScrollPane自动乡下滚动
- Scrapy设置之深入
- 无缝滚动