iOS开发之UIAlertview的事件处理
2013-08-30 14:54
429 查看
原文地址:http://blog.csdn.net/startexcel/article/details/7669920
1.开始想用UIView做密码输入
2.后来觉得麻烦,改用UIAlertview
3.因为我做的是SBSETTINGS开发,不能提供UIAlertView 事件处理所需要的self.说到这个UIAlertView不得不吐槽一下,APPLE绝对是极限方便使用者,非常虐待开发者的.
为了保证流畅,连UIAlertView的YES NO事件都TNND要delegate
UIAlertView和UIActionSheet都采用了Delegate模式,在同一个视图控制器中使用多个UIAlertView或UIActionSheet时控制器需要同时充当它们的delegate,这种情况下处理函数中通常需要通过tag进行区分后处理。这样就经常会造成如下代码:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == LOGIN_ERROR_ALERT) { // it's alert for login error
if (buttonIndex == 0) { // and they clicked OK.
// do stuff
}
}
else if ([alertView tag] == UPDATE_ERROR_ALERT) { // it's alert for update error
if (buttonIndex == 0) { // and they clicked OK.
// do stuff
}
}
else {
}
}
4.这回郁闷了,无法直接用上面的方式处理按钮事件.想想我肯定不是第一个倒霉孩子,果然给我找到一种UIAlsertview block方式
简单来说,这其实就是把按钮事件封装成一个方法块(这说法不严谨),然后把这个块做为参数传递给UIAlertView.实际上还是回调,不过要容易理解也容易处理些.
代理在
https://github.com/jivadevoe/UIAlertView-Blocks
先写好方法块
//调用
别忘记
#include "RIButtonItem.h"
#include "UIAlertView+Blocks.h"
1.开始想用UIView做密码输入
2.后来觉得麻烦,改用UIAlertview
3.因为我做的是SBSETTINGS开发,不能提供UIAlertView 事件处理所需要的self.说到这个UIAlertView不得不吐槽一下,APPLE绝对是极限方便使用者,非常虐待开发者的.
为了保证流畅,连UIAlertView的YES NO事件都TNND要delegate
UIAlertView和UIActionSheet都采用了Delegate模式,在同一个视图控制器中使用多个UIAlertView或UIActionSheet时控制器需要同时充当它们的delegate,这种情况下处理函数中通常需要通过tag进行区分后处理。这样就经常会造成如下代码:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == LOGIN_ERROR_ALERT) { // it's alert for login error
if (buttonIndex == 0) { // and they clicked OK.
// do stuff
}
}
else if ([alertView tag] == UPDATE_ERROR_ALERT) { // it's alert for update error
if (buttonIndex == 0) { // and they clicked OK.
// do stuff
}
}
else {
}
}
4.这回郁闷了,无法直接用上面的方式处理按钮事件.想想我肯定不是第一个倒霉孩子,果然给我找到一种UIAlsertview block方式
简单来说,这其实就是把按钮事件封装成一个方法块(这说法不严谨),然后把这个块做为参数传递给UIAlertView.实际上还是回调,不过要容易理解也容易处理些.
代理在
https://github.com/jivadevoe/UIAlertView-Blocks
先写好方法块
RIButtonItem *cancelItem = [RIButtonItem item]; cancelItem.label = @"No"; cancelItem.action = ^ { //为NO时的处理 }; RIButtonItem *deleteItem = [RIButtonItem item]; deleteItem.label = @"Yes"; deleteItem.action = ^ { //为YES时的处理 [context deleteObject:theObject]; };
//调用
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Delete This Item?" message:@"Are you sure you want to delete this really important thing?" cancelButtonItem:cancelItem otherButtonItems:deleteItem, nil]; [alertView show];
别忘记
#include "RIButtonItem.h"
#include "UIAlertView+Blocks.h"
相关文章推荐
- IOS开发:UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
- iOS开发之用block来实现UIAlertView点击事件的代理方法
- iOS UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
- IOS--UIAlertViewDelegate对对话框的事件处理方法
- ios开发—事件处理与如何获得最佳点击的View
- IOS UIAlertview的事件处理
- IOS UIAlertview的事件处理
- ios开发事件处理之:三 :寻找最合适的view
- iOS开发中Subview的事件响应以及获取subview的方法
- UIAlertView的基本使用和对话框中按钮的事件处理方法
- iOS开发之 UIAlertView 沙盒 归档
- ios中的tablebview点击事件的处理
- ios学习笔记:UIAlertView使用和监听点击事件
- iOS开发 提示框- UIAlertController(是UIAlertView和UIActionSheet的合二为一)
- iOS开发-UI控件:自定义UITableViewCell 上的多个按钮点击事件处理
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- UIAlertView警报-IOS开发
- iOS开发6:UIActionSheet与UIAlertView
- iOS高级开发——CollectionView的cell长按事件实现
- iOS开发-UIImageView响应点击事件