首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件。

具体代码如下:

ViewController.h中的代码如下:

  1. #import <UIKit/UIKit.h>
  2. @interface ViewController : UIViewController<UIAlertViewDelegate>
  3. @end

ViewController.m中的详细代码:

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. // Do any additional setup after loading the view from its nib
  5. //初始化AlertView
  6. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest"
  7. message:@"message"
  8. delegate:self
  9. cancelButtonTitle:@"Cancel"
  10. otherButtonTitles:@"OtherBtn",nil];
  11. //设置标题与信息,通常在使用frame初始化AlertView时使用
  12. alert.title = @"AlertViewTitle";
  13. alert.message = @"AlertViewMessage";
  14. //这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分
  15. alert.tag = 0;
  16. //只读属性,看AlertView是否可见
  17. NSLog(@"%d",alert.visible);
  18. //通过给定标题添加按钮
  19. [alert addButtonWithTitle:@"addButton"];
  20. //按钮总数
  21. NSLog(@"number Of Buttons :%d",alert.numberOfButtons);
  22. //获取指定索引的按钮标题
  23. NSLog(@"buttonTitleAtIndex1:%@",[alert buttonTitleAtIndex:1]);
  24. NSLog(@"buttonTitleAtIndex2:%@",[alert buttonTitleAtIndex:2]);
  25. //获取取消按钮的索引
  26. NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);
  27. //获取第一个其他按钮的索引
  28. NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);
  29. //显示AlertView
  30. [alert show];
  31. [alert release];
  32. }
  33. #pragma marks -- UIAlertViewDelegate --
  34. //根据被点击按钮的索引处理点击事件
  35. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  36. {
  37. NSLog(@"clickButtonAtIndex:%d",buttonIndex);
  38. }
  39. //AlertView已经消失时执行的事件
  40. -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  41. {
  42. NSLog(@"didDismissWithButtonIndex");
  43. }
  44. //ALertView即将消失时的事件
  45. -(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
  46. {
  47. NSLog(@"willDismissWithButtonIndex");
  48. }
  49. //AlertView的取消按钮的事件
  50. -(void)alertViewCancel:(UIAlertView *)alertView
  51. {
  52. NSLog(@"alertViewCancel");
  53. }
  54. //AlertView已经显示时的事件
  55. -(void)didPresentAlertView:(UIAlertView *)alertView
  56. {
  57. NSLog(@"didPresentAlertView");
  58. }
  59. //AlertView即将显示时
  60. -(void)willPresentAlertView:(UIAlertView *)alertView
  61. {
  62. NSLog(@"willPresentAlertView");
  63. }
  64. - (void)viewDidUnload
  65. {
  66. [super viewDidUnload];
  67. // Release any retained subviews of the main view.
  68. // e.g. self.myOutlet = nil;
  69. }

UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法的更多相关文章

  1. 【转】 UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法

    原文网址:http://blog.csdn.net/enuola/article/details/7900346 首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定d ...

  2. (转) UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法

    首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: #import <UIK ...

  3. 在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法

    在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法 最近在做一个小东西,使用kindeditor上传图片的时候,自己写了一个上传的方法,按照协议规则通过ajax返回json ...

  4. 【NX二次开发】修改dlx对话框标题的方法

    修改dlx名称, 修改对话框标题的方法: theDialog->TopBlock()->FindBlock("Dialog")->GetProperties()- ...

  5. Swift - 告警框(UIAlertView)的用法

    1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮 (注:自IOS8起,建议使用UIAlertController) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...

  6. JQuery EasyUI 对话框的使用方法

    下面看一下EasyUI的对话框效果图 js代码: 复制代码代码如下: <script language="javascript" type="text/javasc ...

  7. Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法(通过COM来改造)

    刚有一段时间没做博客了,今天刚好有人问了这个问题,而自己以前也弄过,于是这里有了一篇新的博文. 关于改造WebBrowser控件的一些技巧,大家可以参考MSDN或者蒋晟写的一个东西,里面有讲的很详细的 ...

  8. Eclipse用法:自动生成get和set方法

      方法一 Java的类中,除了常量声明为静态且公有的,一般的对象数据作用域,都是声明为私有的.这样做能保护对象的属性不会被随意改变,调试的时候也会方便很多:在类的公有方法中大一个调用栈就能看到哪里改 ...

  9. adb环境配置+常用adb命令+Logcat命令的用法+手动进行文件比对的方法+批量挪bug

    1. adb环境配置:下载adb环境变量包:打开计算机属性-高级系统设置-环境变量:新建变量adb,值为刚才的环境变量包路径:编辑path值,在最后面加上;%adb%;确定就妥了 2. 常用adb命令 ...

随机推荐

  1. C# 线程--第二线程方法

    概述 上一章节中和大家分享了线程的基础使用方法.在这一章中来和大家分享线程的一些常用方法. 主要包括:线程阻塞,线程终止,线程锁三方面. Thread 的 Sleep 和 Join 方法 Thread ...

  2. C++函数模板本质-学习入门

    template<typename T> void mySwap(T &a, T &b) { T c; c = a; a = b; b = c; } int main() ...

  3. [WCF]IIS部署到新系统

    最近为以前的一个企业部署软件的时候,接触到WCF,通过博客园大佬的系列文章和一些书籍,基本了解了一些.简单说也算是SOA一种方式,提供某种服务,可以理解为一个类库,供其他项目使用,可以做到业务分离.但 ...

  4. From MSI to WiX, Part 4 - Features and Components by Alex Shevchuk

    Following content is directly reprinted from : http://blogs.technet.com/b/alexshev/archive/2008/08/2 ...

  5. 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)

    题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...

  6. java.util.ArrayList源码分析

    public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess ...

  7. [DevExpress]GridControl 列头绘制Checkbox

    关键代码: /// <summary> /// 为列头绘制CheckBox /// </summary> /// <param name="view" ...

  8. C#,PHP对应加密函数

    require_once "JunDes.php"; $jDes=new JunDes(); echo $jDes->encode('98765'); //echo $jDe ...

  9. WCF、WebAPI、WCF REST、Web Service之间的区别

    在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Services.我分享一下我对 ...

  10. PHP获取搜索引擎关键字来源(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)

    <?php //获取来自搜索引擎入站时的关键词 function get_keyword($url,$kw_start) { $start=stripos($url,$kw_start); $u ...