iOS 开发 - iOS 8 以后使用UIAlertController的使用
最近在写项目的时候,发现使用alertview和actonsheet会报警告,所以就查了一下,发现ios 9 以后会使用UIAlertController来进行操作,
具体代码如下:
1、声明
#import "EleventhViewController.h" @interface EleventhViewController ()
{
UIAlertController *_alertController;
} @end
2、使用UIalertController创建的时候,只需要把样式边一样就可以了,如下
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = , -->上拉菜单
UIAlertControllerStyleAlert -->警告框
} NS_ENUM_AVAILABLE_IOS(8_0);
3、警告框的样式
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = ,-->默认的
UIAlertActionStyleCancel,-->取消的
UIAlertActionStyleDestructive -->警告样式,会让字体变成红色
} NS_ENUM_AVAILABLE_IOS(8_0);
3、创建alertview
//alertview的创建
_alertController = [UIAlertController alertControllerWithTitle:@"请选择操作" message:@"数据删除后无法恢复" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { //在这里进行操作 }];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil]; [_alertController addAction:cancelAction];
[_alertController addAction:okAction];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入车牌号"; }];
[self presentViewController:_alertController animated:YES completion:nil];
4、创建actonsheet
//actionsheet的创建
_alertController = [UIAlertController alertControllerWithTitle:@"请选择操作" message:@"数据删除后无法恢复" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:nil]; [_alertController addAction:cancelAction];
[_alertController addAction:okAction];
[_alertController addAction:deleteAction];
[self presentViewController:_alertController animated:YES completion:nil];
5、具体点击方法的实现的话,和alertview标注的一样
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//在这里进行操作
}];
iOS 开发 - iOS 8 以后使用UIAlertController的使用的更多相关文章
- iOS开发-iOS 10 由于权限问题导致崩溃的那些坑
iOS开发-iOS 10 由于权限问题导致崩溃的那些坑 6月份的WWDC大会结束有一段时间了,相信很多开发者也是在努力工作的闲时用着Xcode8 Beta版学习着新的特性吧. 使用Xcode8写自己 ...
- iOS开发--iOS及Mac开源项目和学习资料
文/零距离仰望星空(简书作者)原文链接:http://www.jianshu.com/p/f6cdbc8192ba著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 原文出处:codecl ...
- iOS开发----iOS 8的虚化效果
在iOS 7中,一个重大的改变就是随处可见的虚化,这在通知中心和控制中心表现得尤为抢眼: 然而,当开发人员们着手去将类似的模糊效果增加自己的App的时候,他们会发现有相当严重的障碍. 那时苹果所界定的 ...
- iOS开发——iOS国际化 APP内语言切换
最近一个一直在迭代的老项目收到一份新的开发需求,项目需要做国际化适配,简体中文+英文.由于项目中采用了storyboard和纯代码两种布局方式,所以国际化也要同时实现.上网查了些资料,实现了更改系统语 ...
- iOS开发——iOS学习路线
iOS学习路线 版权声明:欢迎转载,请贴上源地址:http://www.cnblogs.com/iCocos/(iOS梦工厂) 一:自学初步学习路线 二:高级完整学习路线 三:完整知识与能力体系 思维 ...
- IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
摘要 在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错 因为在IOS8中要想设置a ...
- 【转】IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错 因为在IOS8中要想设置appl ...
- iOS开发:iOS中图片与视频一次性多选 - v2m
一.使用系统的Assets Library Framework这个是用来访问Photos程序中的图片和视频的库.其中几个类解释如下 ALAsset ->包含一个图片或视频的各种信息 ALAsse ...
- iOS开发初级课程
iOS开发初级课程 针对学员 掌握Objective C,C或者C++,有语言基础的学员,想从事iOS开发工作. iOS开发那些事-了解iOS开发(8集) 在课程中,我们首先介绍如何使用nib和故事 ...
随机推荐
- 对于火狐浏览器中title不能换行自动变成...怎么解决的?
width: 100px; overflow: hidden; white-space: nowrap; word-break: keep-all; text-overflow: ellipsis;
- vue路由配置,vue子路由配置
上一篇关于vue环境配置已经写好了!按照操作就行了! 现在一个项目已经部署完成,接下来我们从路由开始! 还记得在初始化项目的时候,有提示是否需要安装vue-router,对没错,vue中路由全靠它! ...
- feginclient和hystrix的配置
1.如果设置了 feign: hystrix: enabled: true 则 @FeignClient(value = "service-hi",configuration = ...
- 《CCNA(640-802)全套课程讲义》笔记
路由器: CLI(命令行界面)形式相对应的是GUI (图形用户界面) DTE:数据终端设备,指的是位于用户网络接口的用户端设备,通常情况下,路由器端为DTE端. DCE:数据通讯设备,为通信提供时钟 ...
- web.xml中init-param中的param-name
转载自:http://www.cnblogs.com/hzj-/articles/1689836.html <context-param>的作用:web.xml的配置中<contex ...
- java 读取execl文件
java 中读取execl文件是必要功能,下面说下几种读取方式 1.jxl (支持2003 不支持 2007 貌似最新版支持) /** * 规则设置的模板导入 * @param fi ...
- sqlserver 针对预处理sql传入参数的处理方式
在编写sql中,经常需要对sql进行预处理,动态拼接字符串,那么要获取在这预处理之后返回的的某个值并且赋值,传入参数的语法 USE [OA] GO /****** Object: StoredProc ...
- [转]好用工具:Oracle SQL Developer
我們一直以來就很少使用 Oracle 資料庫,一年下來也頂多 1 ~ 2 個案子採用 Oracle 的資料庫,所以一直都對 Oracle 資料庫的操作不太熟悉,尤其是用 Oracle 內建的那些超難用 ...
- Unity又称Unity Application Block
本文关注以下方面(环境为VS2012..Net Framework 4.5以及Unity 3): Ioc/DI简介: Unity简单示例 一.Ioc/DI简介 IoC 即 Inversion of C ...
- Winform RsaProtectedConfigurationProvider 加密数据库连接字符串
private static string _strProvider = "RsaProtectedConfigurationProvider"; /// <summary& ...