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

基本方法如下

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. 0801 RESTAPI设计,DRF 序列化

    1.内容回顾    1.restframework serializer(序列化)的简单使用                QuereySet([obj,obj,obj])  -->  JSON ...

  2. samtools的基本用法

    1.sam,bam的格式转换: $samtools view -sb file.sam >file.bam $samtools view -sb file.sam -o file.bam #sa ...

  3. photoshop cs5 序列号永久序列号永久激活破解方法

    photoshop cs5 序列号永久序列号永久激活破解方法 (2016-12-10 07:52:21) 转载▼ 标签: it   PhotoShop CS5 /ps5  序列号激活码 1330-15 ...

  4. Android编译系统简要介绍【转】

    本文转载自:http://blog.csdn.net/luoshengyang/article/details/18466779 在Android源码环境中,我们开发好一个模块后,再写一个Androi ...

  5. win10系统下载地址

    Win10正式版微软官方原版ISO系统镜像下载: Win10正式版32位简体中文版(含家庭版.专业版) 文件名: cn_windows_10_multiple_editions_x86_dvd_684 ...

  6. 转-centos7下安装apache服务器httpd的yum方式安装

    转自Clement-Xu的csdn博客 http://blog.csdn.net/clementad/article/details/41620631   Apache在Linux系统中,其实叫“ht ...

  7. java深入探究16-mybatis

    链接:http://pan.baidu.com/s/1skJ4TNB 密码:koo9 1.引入mybatis jsbc简单易学,上手快,非常灵活构建SQL,效率高但代码繁琐,难以写出高质量的代码 hi ...

  8. ComboBoxStyle和ToggleButton

    <Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">   <Setter ...

  9. hdu 1848 Fibonacci again and again(sg)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  10. 51nod 1272 思维/线段树

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1272 1272 最大距离 题目来源: Codility 基准时间限制:1 ...