项目中很多地方会出现弹出框框,来做个判断

基本方法如下

UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"友情提示" message:@"是否确定退出程序" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelA = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

}];

UIAlertAction *configA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

//执行的代码

}];

}];

[alertC addAction:cancelA];

[alertC addAction:configA];

[self presentViewController:alertC animated:YES completion:nil];

因为很多地方都要用到,每次写太麻烦了 ,简单封装一下成为一个工具,提高,,,

1. 创建一个TOOl继承于NSObject

@interface UIAlertTool : NSObject

- (void)initshowAlertView:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message cancel:(NSString        *)cancelButtonTitle other:(NSString *)otherButtonTitle confirmHandle:(void (^)())confirm cancelHandle:(void (^)())cancle;

@end

2.实现部分

#define IAIOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

#import "UIAlertTool.h"

typedef void (^confirm)();

typedef void (^cancle)();

@interface UIAlertTool()

{

confirm confirmParam;

cancle cancleParam;

}

@end

@implementation UIAlertTool

- (void)initshowAlertView:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message cancel:(NSString *)cancelButtonTitle other:(NSString *)otherButtonTitle confirmHandle:(void (^)())confirm cancelHandle:(void (^)())cancle

{ confirmParam = confirm;

cancleParam = cancle;

if (IAIOS8) {

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

cancle();

}];

UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

confirm();

}];

[alertController addAction:cancelAction];

[alertController addAction:otherAction];

[viewController presentViewController:alertController animated:YES completion:nil];

} else{

UIAlertView *TitleAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:otherButtonTitle otherButtonTitles:cancelButtonTitle,nil];

[TitleAlert show];

}

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex==0) {

confirmParam();

} else{

cancleParam();

}

}

@end

UIAlertController UIAlertView用法的更多相关文章

  1. iOS 9.0中UIAlertController的用法

    UIAlertView和UIActionSheet 被划线了. 苹果不推荐我们使用这两个类了.也不再进行维护和更新 正如苹果所说它现在让我们用UIAlertConntroller 并设置样式为UIAl ...

  2. UIAlertView用法

    1. 最简单的用法 UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"这是一个简 ...

  3. swift - UIAlertController 的用法

    ios 8 以后苹果官方建议使用UIAlertController这个类,所以专门去网上找资料,了解了下用法, 1.创建一个alertController let alertController = ...

  4. iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)

     本文转载至 http://blog.csdn.net/liuwuguigui/article/details/39494597       IOS8UIAlertViewUIActionSheet ...

  5. iOS 9.0中UIAlertController的用法。

    1.我为什么要写这篇博客记录它? 答:因为 UIAlertView和UIActionSheet 被划线了 苹果不推荐我们使用这两个类了,也不再进行维护和更新,为了以后方便使用我来记录一下.如图所示 正 ...

  6. UIAlertController 部分用法及属性

    //创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...

  7. iOS开发之UIAlertView与UIAlertController的详尽用法说明

    本文将从四个方面对IOS开发中UIAlertView与UIAlertController的用法进行讲解: 一.UIAlertView与UIAlertController是什么东东? 二.我们为什么要用 ...

  8. iOS引用当前显示的UIAlertView

    UIAlertView在iOS里和一般的UIView不一样,有时候使用起来会有一些不便.特别要引用当前显示的UIAlertView的时候,就存在一些难度. 在iOS7以前,可以下面的代码可以解决这个问 ...

  9. iOS8新特性(1)——UIAlertController

    一.iOS8介绍 iOS8 新特性,主要是UI上进行了统一 1.UIAlertController 2.UIPresentaionController:管理所有通过modal出来的控制器(看笔记) 3 ...

随机推荐

  1. 跨平台移动开发 Android使用JPush推送消息

    二话不说,直接上图,看效果 第一步在官网下载 Android Push SDK https://www.jpush.cn/sdk/android 第二步 创建注册帐号,应用 第三步  下载应用,导入l ...

  2. POJO、Bean和JavaBean

    本文总结自: https://blog.csdn.net/chenchunlin526/article/details/69939337 POJO (plain pld java object) 一个 ...

  3. php数组函数-array_flip()

    array_flip()函数返回一个反转后的数组,如果同一个值出现多次,则最 后一个键名作为它的值,所有其他的键名将丢失. 如果原数组中的值得数据类型不是字符串或整数,函数将报错. array_fli ...

  4. INSPIRED启示录 读书笔记 - 第9章 产品副经理

    发现帮手 从本质上讲,产品就是创意,产品经理的职责是想出好点并加以实现.我们需要好点子,有些想法是我们自己的创意,但如果仅依靠自己,就会严重限制创意的发挥 做产品要找公司最聪明的人合作,发现公司里潜在 ...

  5. Vue.js学习笔记 第三篇 条件渲染

    条件选择 条件选择的用法和其他语言类似,一个例子就能解决所有问题 <!DOCTYPE html> <html> <head> <meta charset=&q ...

  6. 数据结构与算法之美 06 | 链表(上)-如何实现LRU缓存淘汰算法

    常见的缓存淘汰策略: 先进先出 FIFO 最少使用LFU(Least Frequently Used) 最近最少使用 LRU(Least Recently Used) 链表定义: 链表也是线性表的一种 ...

  7. hadoop 输出中文乱码问题

    本文转载至: http://www.aboutyun.com/thread-7358-1-1.html hadoop涉及输出文本的默认输出编码统一用没有BOM的UTF-8的形式,但是对于中文的输出wi ...

  8. js状态模式

    状态模式,当一个对象的内在状态改变时允许改变其行为,这个对象看起来是改变了其类. 状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况.把状态的判断逻辑转移到表示不同状态的一系列类当 ...

  9. 导入别人struts2项目可能要做的改变

    然后: 接着 再接着 最后

  10. Mac上的抓包工具Charles[转载]

    今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/198 ...