UIAlertController UIAlertView用法
项目中很多地方会出现弹出框框,来做个判断
基本方法如下
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用法的更多相关文章
- iOS 9.0中UIAlertController的用法
UIAlertView和UIActionSheet 被划线了. 苹果不推荐我们使用这两个类了.也不再进行维护和更新 正如苹果所说它现在让我们用UIAlertConntroller 并设置样式为UIAl ...
- UIAlertView用法
1. 最简单的用法 UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"这是一个简 ...
- swift - UIAlertController 的用法
ios 8 以后苹果官方建议使用UIAlertController这个类,所以专门去网上找资料,了解了下用法, 1.创建一个alertController let alertController = ...
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
本文转载至 http://blog.csdn.net/liuwuguigui/article/details/39494597 IOS8UIAlertViewUIActionSheet ...
- iOS 9.0中UIAlertController的用法。
1.我为什么要写这篇博客记录它? 答:因为 UIAlertView和UIActionSheet 被划线了 苹果不推荐我们使用这两个类了,也不再进行维护和更新,为了以后方便使用我来记录一下.如图所示 正 ...
- UIAlertController 部分用法及属性
//创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...
- iOS开发之UIAlertView与UIAlertController的详尽用法说明
本文将从四个方面对IOS开发中UIAlertView与UIAlertController的用法进行讲解: 一.UIAlertView与UIAlertController是什么东东? 二.我们为什么要用 ...
- iOS引用当前显示的UIAlertView
UIAlertView在iOS里和一般的UIView不一样,有时候使用起来会有一些不便.特别要引用当前显示的UIAlertView的时候,就存在一些难度. 在iOS7以前,可以下面的代码可以解决这个问 ...
- iOS8新特性(1)——UIAlertController
一.iOS8介绍 iOS8 新特性,主要是UI上进行了统一 1.UIAlertController 2.UIPresentaionController:管理所有通过modal出来的控制器(看笔记) 3 ...
随机推荐
- 键盘keyCode
字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L 76 U 85 ...
- NoSQL数据库memcache和redis区别
在web后台发开面试中,经常会被问道memcache和redis的区别和使用情况. 其中memcache和redis都是基于内存存储的缓存系统,存储形式key--value键值对的形式. 区别: 1. ...
- iOS上架被拒原因及解决办法
简单的记录一下,近期APP上架所遇到的坑爹事儿吧!! 第一次提交: 第二天给了回复,内容如下: .Guideline - Performance - Software Requirements You ...
- JAVA基础补漏--基础数据类型与引用数据类型
==在不同数据类型中意义不同. 在基础数据类型中,表示的是数值的比较. 在引用数据类型中,表示的是内存地址值的比较. 一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit), ...
- java基础11(IO流)-字符流
转换流 由于字节流操作中文不是特别方便,所以java中提供了转换流 编码表:由现实世界的字符和对应的数值组成的一张表 编码:把看得懂的变成看不懂的(String-------byte[]) 解码:把看 ...
- HDFS存档
Hadoop存档 每个文件均按块方式存储,每个块的元数据存储在namenode的内存中,因此Hadoop存储小文件会非常低效.因为大量的小文件会耗尽namenode中的大部分内存.存储小文件所需的磁盘 ...
- kafka原理学习好文
摘自:http://blog.csdn.net/suifeng3051/article/details/48053965 http://blog.csdn.net/ychenfeng/article/ ...
- 可编辑的div模仿文本框缓存(使用AUTOCOMPLETE属性,off是不缓存,on是缓存(默认))
用session实现的, 1.进当前页面就从session(a)中取( sessionStorage.getItem )(不管存在不存在,后续有合理的存储和删除); 2.离开当前页时删除这个sessi ...
- jquery事件优化---事件委托
假如你有一个表格,里面有大量的td 而你需要做的事就是,给td绑定点击事件函数, 那么多的td,遍历单元格和为每一个单元格绑定事件处理函数将会大大降低代码的性能, 如果让单元格的父元素监听事件,只要判 ...
- (转)Openstack Cascading和Nova Cell
Openstack是看着AWS成长起来的,这点毋庸置疑:所以AWS大规模商用已成事实的情况下,Openstack也需要从架构和产品实现上进行优化,以满足大规模商用的要求.从已有的实现来看其中两种方式值 ...