#import <Foundation/Foundation.h>

typedef void (^DismissBlock)(int buttonIndex);
typedef void (^CancelBlock)(); @interface UIAlertView (Blocks) <UIAlertViewDelegate> + (UIAlertView*) showAlertViewWithTitle:(NSString*) title
message:(NSString*) message
cancelButtonTitle:(NSString*) cancelButtonTitle
otherButtonTitles:(NSArray*) otherButtons
onDismiss:(DismissBlock) dismissed
onCancel:(CancelBlock) cancelled; @end
//
// UIAlertView+Blocks.m
// UIKitCategoryAdditions
// #import "UIAlertView+Blocks.h" static DismissBlock _dismissBlock;
static CancelBlock _cancelBlock; @implementation UIAlertView (Blocks) + (UIAlertView*) showAlertViewWithTitle:(NSString*) title
message:(NSString*) message
cancelButtonTitle:(NSString*) cancelButtonTitle
otherButtonTitles:(NSArray*) otherButtons
onDismiss:(DismissBlock) dismissed
onCancel:(CancelBlock) cancelled { _cancelBlock = [cancelled copy]; _dismissBlock = [dismissed copy]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:[self self]
cancelButtonTitle:cancelButtonTitle
otherButtonTitles:nil]; for(NSString *buttonTitle in otherButtons)
[alert addButtonWithTitle:buttonTitle]; [alert show];
return alert;
} + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger) buttonIndex { if(buttonIndex == [alertView cancelButtonIndex])
{
_cancelBlock();
}
else
{
_dismissBlock(buttonIndex - ); // cancel button is button 0
}
} @end
 

UIAlertView+Blocks.h的更多相关文章

  1. iOS:简单使用UIAlertVIew和UIActionSheet

    做iOS开发的同学想必都用过UIAlertVIew或者UIActionSheet.UIAlertVIew 可以弹出一个出现在屏幕中间的提示视图,给用户展示信息,并让用户自己选择操作,UIActionS ...

  2. ios开发 <AppName>-Prefix.pch文件的用法详解

    我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch.对于这个 ...

  3. IOS之表视图单元格删除、移动及插入

    1.实现单元格的删除,实现效果如下 - (void)viewDidLoad { [super viewDidLoad]; //设置导航栏 self.editButtonItem.title = @&q ...

  4. Objective-C Runtime之着魔的UIAlertView

    前言: 上篇文章写的是Runtime的一个入门教程,刚哥问我那个Associated Objects加回调是啥时候用,那我就来告诉你啦!我们在使用UIAlertView的时候用的多. 传统的UIAle ...

  5. 防止多个UIAlertView重叠弹出

    http://www.jianshu.com/p/7ac398ef4532 项目中可能会遇到这种情况,好几个alertView因为逻辑关系全部弹出,用户需要一个个的点击才能将所有的alertView取 ...

  6. (转载)iOS Framework: Introducing MKNetworkKit

    This article is available in Serbo-Croatian,  Japanese and German. (Translations in Serbo-Croatian b ...

  7. BlocksKit的使用

    一.引言 众所周知Block已被广泛用于iOS编程.它们通常被用作可并发执行的逻辑单元的封装,或者作为事件触发的回调.Block比传统回调函数有2点优势: 允许在调用点上下文书写执行逻辑,不用分离函数 ...

  8. ZFPlayer 源码解读

    源码下载地址:https://github.com/renzifeng/ZFPlayer 之前自己实现过一个模仿百思不得姐的demo https://github.com/agelessman/FFm ...

  9. iOS开发常见BUG和一些小技巧(ps:耐心看完,很实用)

    [385][scrollView不接受点击事件,是因为事件传递失败] // // MyScrollView.m // Created by beyond on 15/6/6. // Copyright ...

随机推荐

  1. Sublime Text 3安装AngularJS插件

    Sublime Text 3是目前笔者用过的最好用的代码编辑器之一,界面如下图所示: 我们可以用该编辑器开发AngularJS应用,首先需要安装AngularJS提示插件. 需要以下几步: 1.安装P ...

  2. make与makefile的几个例子和(自己写一下,汗!忘记了!)总结

    共用的几个源代码文件: main.c 2.c 3.c 代码依次为: #include<stdlib.h> #include "a.h" extern void func ...

  3. 快速WCF

    初级原理:通得过地址调用接口服务,接口服务调用对应实现方法 援引文章地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049. ...

  4. sparkmlib-相关系数

    一.基本原理 在stat包中实现了皮尔逊(Pearson)与 斯皮尔曼(Spearman)两类相关系数的计算 (1)Pearson:   (x,y)协方差/[(x标准方差)*(y标准方差)] 详情可以 ...

  5. Xcode5 如何添加一个Github/Repository 并且Checkout

    1. 添加一个Account  也就是添加一个 Repository. In Xcode, choose Xcode > Preferences, and click Accounts. Pre ...

  6. WPF中窗体在同一个位置实现不同页面切换

    要想在WPF窗体中实现不同页面切换,我们就需要用到ContentControl这个控件,这个控件的位置和大小就是你要显示页面的位置和大小. 下面举例说明: Xaml: <Grid> < ...

  7. C++ _ const的用法,特别是用在函数前面与后面的区别!

    在普通的非 const成员函数中 this的类型是一个指向类类型的 const指针.可以改变this所指向的值,但不能改变 this所保存的地址. 在 const成员函数中 this的类型是一个指向 ...

  8. Hibernate映射文件配置(hbm.xml和注解方式)

    一:通过*.hbm.xml配置实体的实现方式 mappingResources用于指定少量的hibernate配置文件像这样 Xml代码  <property name="mappin ...

  9. Bootstrap历练实例:禁用的按钮

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  10. Avada v5.0.6 最新版本破解教程如下:

    Avada v5.0.6 最新版本破解教程如下: .找到\themes\Avada\includes\avada-envato-api.php文件,注释掉如下两行代码 $response_code = ...