原始的UIAlertView的需要通过委托方法来实现按钮点击事件,需要设置代理,实现委托方法,比较繁琐。我们可以自定义一个UIAlertView类,通过block语法替代委托代理,这样的话,使用该自定义的UIAlertView就比较方便了。
BlockUIAlertView.h 文件
[cpp] view plaincopy
- typedef void(^AlertBlock)(NSInteger);
- @interface BlockUIAlertView : UIAlertView
- @property(nonatomic,copy)AlertBlock block;
- - (id)initWithTitle:(NSString *)title
- message:(NSString *)message
- cancelButtonTitle:(NSString *)cancelButtonTitle
- clickButton:(AlertBlock)_block
- otherButtonTitles:(NSString *)otherButtonTitles;
- @end
BlockUIAlertView.m 文件的实现
[cpp] view plaincopy
- #import "BlockUIAlertView.h"
- @implementation BlockUIAlertView
- @synthesize block;
- - (id)initWithTitle:(NSString *)title
- message:(NSString *)message
- cancelButtonTitle:(NSString *)cancelButtonTitle
- clickButton:(AlertBlock)_block
- otherButtonTitles:(NSString *)otherButtonTitles {
- self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles,nil];
- if (self) {
- self.block = _block;
- }
- return self;
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- self.block(buttonIndex);
- }
- @end
该自定义的BlockUIAlertView的调用
[cpp] view plaincopy
- BlockUIAlertView *alertView = [[BlockUIAlertView alloc] initWithTitle:@"提示" message:@"block测试" cancelButtonTitle:@"取消title" clickButton:^(NSInteger indexButton){
- NSLog(@"%d",indexButton);
- } otherButtonTitles:nil];
- [alertView show];
发表评论
-
如何使用AV Foundation从摄像头将视频帧捕获为图像
2012-11-15 17:21 7382如果译错,感谢指出。 英文原文地址:https://d ... -
iOS单元测试
2012-11-05 11:37 864转自:http://www.cnblogs.com/ke ... -
Core Data数据持久化的使用
2012-10-30 21:31 1005CoreData 是ios中用来对数据做持久化的一个框架 ... -
ASIHTTPRequest缓存策略的设置
2012-10-30 17:23 3827ASIHTTPRequest 是一款强大的网络请求框架,该框架 ... -
【无限互联】xcode自定义类的模板
2012-10-23 19:37 1110翻译:http://www.bobmccune.com/ ... -
【无限互联】适配iOS6和iPhone5屏幕
2012-10-23 18:05 24251. iOS6的mo模拟器比较大,通过comman ... -
【无限互联】mac下配置svn服务器
2012-10-22 13:30 724在mac下配置svn服务器其实很简单,只需要简单的几句命令就可 ... -
【无限互联】iOS开发之多线程开发
2012-10-10 17:41 1203本节要点: 1.多线程的概念 2.掌握iOS中多线程 ... -
Objective-C新特性
2012-09-05 14:38 658基于Xcode4.4(不完全独有)。1. 成员方法无需前置声明 ... -
iphone-NSDate日期处理
2012-08-31 16:25 1022NSDate存储的是世界标准时(UTC),输出时需要 ... -
iphone开发资源汇总
2012-08-31 16:16 1564如何用Facebook graphic api上传视 ... -
iOS-如何让xcode自动检查内存泄露
2012-08-31 16:05 1054在project-setting中找到 “Run Static ... -
UIScrollView的属性总结
2012-02-08 15:58 4385在滚动过程当中,其实是在修改原点坐标 当手指触摸后, scr ... -
iPhone开发之 ARC是什么
2012-01-17 16:58 1327相关链接:http://blog.csdn ... -
画图时 自己做的一小笔记
2012-01-07 21:02 9200 CGContextRef context = UIGra ... -
让Xcode 4.2生成的app支持旧版iOS设备(armv6)
2012-01-07 00:46 1281这几天遇到一个非常奇怪的问题,基于Xcode 4.2开发的ap ... -
5个开源库的JSON解析速度测试
2011-12-03 23:15 1409iOS5新增了JSON解析的API ... -
获取iOS设备当前ip地址
2011-11-17 23:16 1338第一种方法是用系统api的方式获取,如下 #include & ... -
Quartz 2D编程指南(2) - 图形上下文(Graphics Contexts)
2011-11-12 00:08 1393一个Graphics Context表示一 ... -
Quartz 2D编程指南(1) - 概览
2011-11-11 23:57 1651Quartz 2D是一个二维图形绘制引擎,支持iOS环境和Ma ...
相关推荐
1.系统的UIAlertView使用方便,但是有时需要三个按钮,这时的UIAlertView会出现问题,三个按钮的默认摆放位置,不尽人意 2.使用UIAlertView的Delegate,来修改其布局
iOS程序中的Action Sheet就像Windows中的 “确定-取消”对话框一样,用于强制用户进行选择。当用户将要进行的操作具有一定危险时,常常使用Action Sheet对用户进行危险提示,这样,用户有机会进行取消操作。 Alert...
https://github.com/STShenZhaoliang/STAlertView 400行写的自定义UIAlertView,没有开太多接口,大家可以自由修改。
ios应用源码之仿uialertview和uiactionsheet的一个效果
IOS应用源码之仿UIAlertView和UIActionSheet的一个效果 .rar
ios7 自定义UIAlertView ios7 UIAlertView 弹出 警告 自定义 简单实用。 支持转屏
自定义 UIAlertView
作者paozi-jun,源码YYAlertView,Swift 语言编写自定义控件, 实现一个自定义的UIAlertView 。
因为iOS8 以后UIAlertView已经不推荐使用 所以自己简单封装了一下UIAlertView 和 UIAlertController 根据系统自动选择 封装的比较简单 为了方便使用而已
NULL 博文链接:https://ikrboy.iteye.com/blog/2002976
IOS应用源码——仿UIAlertView和UIActionSheet的一个效果.zip
iphone中的基础控件UIAlertView,适合初学者,主要学习UIAlertView的常用属性设置、点击事件、添加其他视图到UIAlertView上等
封装体统的UIAlertView,使用Block传递数据。
NULL 博文链接:https://dingran.iteye.com/blog/1770376
let alrtView = ChoiceAlrtView() @IBAction func OutLogin(_ sender: UIButton) { alrtView.showChoice(str: "确认退出吗") alrtView.resualtBlock = {(isTrue : Bool) in if isTrue { print("是") ...
仿IOS风格弹窗,效果还不错,兼容html5,原效果页面地址: http://www.jq22.com/demo/uiAlertView201712071705/# 此源代码存在bug,嵌套弹出框时,后面的弹出将无效。 此版本我已修正过,在项目中正常使用。 这里...
swift - UIAlertView的使用
苹果ios开发100个实例源码; 个人信息输入表(支持表单增删) 二维码扫描应用demo 二维码生成器 从GIF动画创建一个动态UIImages 对象 从上往下拉出现加载view,动态加载内容 从上往下拉动态加载 从上往下拉动态加载3 ...
一个简单的封装UIalertView,可以达到展示列表的目的