为UIAlertView添加block支持
来源:互联网 发布:淘宝店铺广告语 编辑:程序博客网 时间:2024/05/17 01:03
系统自带的UIAlertView只能支持delegate方式. 如果你只有一个UIAlertView这种方式可能无关紧要. 但如果你有二个或多个UIAlertView, 你需要在委托方法中进行判断是哪个UIAlertView实例的产生的委托, 接着又要判断是响应哪个button. 如果你曾经这样做过, 想想这是多杂的代码. Objective-C是支持块代码的, 如果对UIAlertView添加块支持, 那岂不是一个美事.
这里推荐一个开源的实现: https://github.com/jivadevoe/UIAlertView-Blocks
如果你的项目使用Cocoapods管理. 在Podfile添加下面代码增加支持
pod "UIAlertView-Blocks", "~> 1.0"
再使用命令更新
pod update
使用方式
// 添加头文件#import <UIAlertView+Blocks.h>NSString *title = NSLocalizedString(@"Alert", nil);NSString *message = NSLocalizedString(@"UIAlertView-Blocks", nil);NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);NSString *otherTitle = NSLocalizedString(@"Set", nil);RIButtonItem *cancelButtonItem = [RIButtonItem itemWithLabel:cancelButtonTitle action:^{ NSLog(@"Press Button Cancel");}];RIButtonItem *otherButtonItem = [RIButtonItem itemWithLabel:otherTitle action:^{ NSLog(@"Press Button OK");}];UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message cancelButtonItem:cancelButtonItem otherButtonItems:otherButtonItem, nil];[alert show];除了这种使用方式, UIAlertView-Blocks还支持其它方法, 可以参考一下它的github主页.
0 0
- 为UIAlertView添加block支持
- 为UIAlertView添加block支持
- 给UIAlertView UIActionSheet 添加block支持
- 给UIAlertView UIActionSheet 添加block支持
- UIAlertView + Block
- 利用Associative机制为UIAlertView添加一个Block属性,将AlertView与button的响应事件关联
- 使用第三方的支持Block 的UIAlertView
- 为一个view添加UIAlertview动画效果
- UIAlertView使用Block回调
- UIAlertView 加Block 扩展
- uialertview block 回调
- 如何为moodle block添加icon?
- 为应用程序添加脚本支持
- 为应用程序添加脚本支持
- 为DWR添加CDI支持
- 为qxmpp添加 AdHocCommand 支持
- 为Vim 添加vimgdb支持
- 为freeswitch 添加h323支持
- uvalive5092(找规律)
- 关于JAVA类的初始化顺序
- JAVA中获取一个时间中的年月日
- 数年不关注,Everything for windows已经进化得很厉害了
- 用定时器1控制四位数码管从6432减到6393保持住这个数值,同时用定时器0控制流水灯从上至下以500ms移动同时停止!!!然后流水灯全部闪烁2.4秒后熄灭!继而数码管上显示6666
- 为UIAlertView添加block支持
- 辛星浅析utf8中比较常见的utf8校对集
- Android 控件之九:DatePicker日期选择控件 DatePickerDialog日期选择对话框
- C++面试常见题目问与答(汇总二)
- EventBus的初步使用:
- A. Bear and Elections
- Android 控件之十:ProgressBar进度条
- C语言基础
- XSLT