利用这种方式可以避免继承Delegate,不然有很多UIAlertview的时候,处理起来就麻烦了。有效地达到了代码分层的好处。
1.添加头文件,文件请见附件。具体用法可以参照:https://github.com/jivadevoe/UIAlertView-Blocks
#include "RIButtonItem.h" #include "UIAlertView+Blocks.h"
2.实现代码,下面的方法是一个UIButton触发的点击事件的自定义方法
//弹出警告框,并实现警告框按钮的触发事件 - (IBAction)showAlert:(UIButton *)sender forEvent:(UIEvent *)event { RIButtonItem *cancelItem = [RIButtonItem item]; cancelItem.label = @"No"; cancelItem.action = ^ { //为NO时的处理 NSLog(@"为NO时的处理"); }; RIButtonItem *confirmItem = [RIButtonItem item]; confirmItem.label = @"Yes"; confirmItem.action = ^ { //为YES时的处理 NSLog(@"为YES时的处理"); }; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete This Item?" message:@"Are you sure you want to delete this really important thing?" cancelButtonItem:cancelItem otherButtonItems:confirmItem, nil]; [alert show]; }
相关推荐
1.系统的UIAlertView使用方便,但是有时需要三个按钮,这时的UIAlertView会出现问题,三个按钮的默认摆放位置,不尽人意 2.使用UIAlertView的Delegate,来修改其布局
一,效果图。... UIAlertView* alert = [[UIAlertView alloc]initWithTitle:nil message:@此信息3秒后消失 delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; [alert show]; [self p
– (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /**/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles,...
整合了UIAlertView和UIActionSheet这两种系统风格的弹框,创建弹框再也不用兼容iOS8以前和iOS8以后了。代码也不会因为delegate而分离,直接接受Block回调。如果您觉得我的代码帮到了您,我会非常欣慰。同时如果您想...
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"LTPickerView" message:[NSString stringWithFormat:@"选择了第%d行的%@",num,str] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", ...
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello" message:@"zhu" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alert show]; } 8.右键单击View中添加的按钮分别添加...
iOS开发之UIlabel多行文字自动换行 (自动折行) UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, ...
IOS 中弹框的实现方法整理 #define iOS8Later ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) ios 8以前的弹框 @interface RootViewController ()<UIAlertViewDelegate> @end UIAlertView * ...
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"用户名不能为空" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil]; //show 展现 ,显示alertview [alertView ...
iOS 5 Programming Cookbook by Vandad Nahavandipoor Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix...
但是通过delegate 方法处理按钮事件并不方便。 现在我们可以向 UIAlertAction 添加按钮事件,我们可以通过 UIAlertAction 使用 Block。 那么 UIAlertController 有两种样式:UIAlertControllerStyleActionSheet、...
动画效果和外观非常匹配iOS 7中的UIAlertView;警示框支持多个按钮和数量各异的文本;可选自定义内容视图;可更换标题/信息/内容视图;可为独特的警示提醒自定义主题;可为独特的警示提醒自定义文本框 可自定义按钮 ...
Init、Delegate 也是如此。 在 iOS5、6、7、8 上运行。 不使用ARC。你需要什么 如何使用- ( void )more{ FSAlertView *moreAlert = [[FSAlertView alloc ] initWithTitle: @" title " message: @" the FSAlertView ...
源码LKAlarmManager, 方便快捷的把 “您的提醒” 加入到 日历或者本地通知中,会自动处理本地通知超过64个的情况,注册下 LKAlarmManager 回调,在接收到提醒的时候,就可以做你想做的事。 使用方法: 使用例子 :...
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"开启隐藏功能" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView show]; }];
目前市面上提供的第三方SDK,相当繁琐臃肿,还需要去他们的集成平台上注册各种key之类的,相当麻烦.CC轻量级开放平台服务提供一行代码请求数据服务,底层集成了各平台SDK,用户无需关心具体平台的实现,省事省心....
来源:Licence:BSD平台:iOS设备:...这份代码实现的Alert View是基于UIView,而不是UIAlertView,使用的是 Block 技术,即不需要delegate函数。支持ARC。 Code4App编译测试,适用环境:Xcode 4.5, iOS 5.0 以上。
为UIAlertView、UIActionSheet、UIControl的所有子类(UIButton,UIDataPicker 等等)添加使用 Block 的回调,代替delegate和target 和 selector。 小编注:感谢开发者@张玺cc 分享代码于Code4App。 Code4App编译...
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您当前点击的是第%d个按钮",index] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];...