最近在写项目的时候,发现使用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的使用的更多相关文章

  1. iOS开发-iOS 10 由于权限问题导致崩溃的那些坑

     iOS开发-iOS 10 由于权限问题导致崩溃的那些坑 6月份的WWDC大会结束有一段时间了,相信很多开发者也是在努力工作的闲时用着Xcode8 Beta版学习着新的特性吧. 使用Xcode8写自己 ...

  2. iOS开发--iOS及Mac开源项目和学习资料

    文/零距离仰望星空(简书作者)原文链接:http://www.jianshu.com/p/f6cdbc8192ba著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 原文出处:codecl ...

  3. iOS开发----iOS 8的虚化效果

    在iOS 7中,一个重大的改变就是随处可见的虚化,这在通知中心和控制中心表现得尤为抢眼: 然而,当开发人员们着手去将类似的模糊效果增加自己的App的时候,他们会发现有相当严重的障碍. 那时苹果所界定的 ...

  4. iOS开发——iOS国际化 APP内语言切换

    最近一个一直在迭代的老项目收到一份新的开发需求,项目需要做国际化适配,简体中文+英文.由于项目中采用了storyboard和纯代码两种布局方式,所以国际化也要同时实现.上网查了些资料,实现了更改系统语 ...

  5. iOS开发——iOS学习路线

    iOS学习路线 版权声明:欢迎转载,请贴上源地址:http://www.cnblogs.com/iCocos/(iOS梦工厂) 一:自学初步学习路线 二:高级完整学习路线 三:完整知识与能力体系 思维 ...

  6. IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送

    摘要 在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错 因为在IOS8中要想设置a ...

  7. 【转】IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送

    在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错 因为在IOS8中要想设置appl ...

  8. iOS开发:iOS中图片与视频一次性多选 - v2m

    一.使用系统的Assets Library Framework这个是用来访问Photos程序中的图片和视频的库.其中几个类解释如下 ALAsset ->包含一个图片或视频的各种信息 ALAsse ...

  9. iOS开发初级课程

    iOS开发初级课程 针对学员 掌握Objective  C,C或者C++,有语言基础的学员,想从事iOS开发工作. iOS开发那些事-了解iOS开发(8集) 在课程中,我们首先介绍如何使用nib和故事 ...

随机推荐

  1. mysql 5.7以上版本安装配置方法图文教程(mysql 5.7.12\mysql 5.7.13\mysql 5.7.14)(转)

    http://www.jb51.net/article/90302.htm ******************************* 这篇文章主要为大家分享了MySQL 5.7以上缩版本安装配置 ...

  2. LeetCode: Permutations 解题报告

    Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] ha ...

  3. 使用yum时出现的404

    今天使用yum升级nss yum update nss 结果爆出错误: http://people.centos.org/tru/devtools-2/6Server/x86_64/RPMS/repo ...

  4. python AES 加密

    pad: ZeroPadding mode: cbc #!/usr/bin/env python# -*- coding:utf-8 -*-# 这里使用pycrypto‎库# 按照方法:easy_in ...

  5. eclipse下properties配置文件中文乱码解决

    properties文件常带有中文注释,eclipse显示是乱码. 安装插件(properties editor)可以解决properties配置文件乱码的问题. 菜单 : Help->Ecli ...

  6. iOS文件和目录操作,iOS文件操作,NSFileManager使用文件操作:

    NSFileManager常用的文件方法: -(NSData*)contentsAtPath:path 从一个文件中读取数据 -(BOLL)createFileAtPath:path contents ...

  7. JavaScript 使用 php 的变量

    php 里面有一个变量,我想让 js 调用他, 有如下流程: <?php for ($i = 0; $i < 8; $i++) { echo "<tr>"; ...

  8. uboot中DEBUG定义

    uboot的debug定义在include/common.h中 #ifdef DEBUG #define debug(fmt, args...)  printf(fmt, ##args) #defin ...

  9. [转]Private Libraries、Referenced Libraries、Dependency Libraries的区别

    一.v4.v7.v13的作用和用法 1.Android Support V4, V7, V13是什么? 本质上就是三个java library. 2.为什么要有support库?   是为了解决软件的 ...

  10. ios两视图间托付(delegate)传值

    现有两个视图(ViewController.ViewController1),从ViewController中带參数跳转到ViewController1,在ViewController1选中数据后带有 ...