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

基本方法如下

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

最新文章

  1. 关于JQuery简单介绍
  2. 将U盘分成 启动盘+文件存储区
  3. js 鼠标上移 图片放大
  4. 【flash】关于flash的制作透明gif的一个小技巧
  5. VS2010 MFC GDI+ 实现PNG透明图片显示
  6. UVA 11478 Halum(差分约束)
  7. C#奇葩关键字
  8. 理解margin负值
  9. 《设计模式》学习&理解&总结
  10. git 入门教程之冲突合并
  11. Java 获取屏幕的宽、高
  12. request和session的区别
  13. android:如何通过自定义工程模板让新建的工程都默认支持lambda表达式
  14. Spark SQL读取Oracle的number类型的数据时精度丢失问题
  15. javaweb 学习系列【转】
  16. vue-cli+webpack在生成的项目中使用bootstrap方法(二)
  17. UI设计,使用 线框图(页面示意图或页面布局图)
  18. 3dmax坐标系与导出fbx的坐标系
  19. BJOI 模拟赛 #3 题解
  20. 导出excel设置样式(Aspose.Cells)

热门文章

  1. 【鸟哥的Linux私房菜】笔记3
  2. 默认连接电脑的模式为MTP【转】
  3. java 监控命令
  4. ZooKeeper服务-操作(API、集合更新、观察者、ACL)
  5. whois老域名挖掘技术
  6. Codeforces Round #275 (Div. 2) D
  7. Ubuntu 没有mkinitrd 解决方法
  8. ambari2.4.2在CentOS7上的二次开发
  9. cos用在什么场景
  10. Ant入门