UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件。
具体代码如下:
ViewController.h中的代码如下:
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController<UIAlertViewDelegate>
- @end
ViewController.m中的详细代码:
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib
- //初始化AlertView
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest"
- message:@"message"
- delegate:self
- cancelButtonTitle:@"Cancel"
- otherButtonTitles:@"OtherBtn",nil];
- //设置标题与信息,通常在使用frame初始化AlertView时使用
- alert.title = @"AlertViewTitle";
- alert.message = @"AlertViewMessage";
- //这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分
- alert.tag = 0;
- //只读属性,看AlertView是否可见
- NSLog(@"%d",alert.visible);
- //通过给定标题添加按钮
- [alert addButtonWithTitle:@"addButton"];
- //按钮总数
- NSLog(@"number Of Buttons :%d",alert.numberOfButtons);
- //获取指定索引的按钮标题
- NSLog(@"buttonTitleAtIndex1:%@",[alert buttonTitleAtIndex:1]);
- NSLog(@"buttonTitleAtIndex2:%@",[alert buttonTitleAtIndex:2]);
- //获取取消按钮的索引
- NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);
- //获取第一个其他按钮的索引
- NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);
- //显示AlertView
- [alert show];
- [alert release];
- }
- #pragma marks -- UIAlertViewDelegate --
- //根据被点击按钮的索引处理点击事件
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- NSLog(@"clickButtonAtIndex:%d",buttonIndex);
- }
- //AlertView已经消失时执行的事件
- -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
- {
- NSLog(@"didDismissWithButtonIndex");
- }
- //ALertView即将消失时的事件
- -(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
- {
- NSLog(@"willDismissWithButtonIndex");
- }
- //AlertView的取消按钮的事件
- -(void)alertViewCancel:(UIAlertView *)alertView
- {
- NSLog(@"alertViewCancel");
- }
- //AlertView已经显示时的事件
- -(void)didPresentAlertView:(UIAlertView *)alertView
- {
- NSLog(@"didPresentAlertView");
- }
- //AlertView即将显示时
- -(void)willPresentAlertView:(UIAlertView *)alertView
- {
- NSLog(@"willPresentAlertView");
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法的更多相关文章
- 【转】 UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
原文网址:http://blog.csdn.net/enuola/article/details/7900346 首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定d ...
- (转) UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: #import <UIK ...
- 在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法
在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法 最近在做一个小东西,使用kindeditor上传图片的时候,自己写了一个上传的方法,按照协议规则通过ajax返回json ...
- 【NX二次开发】修改dlx对话框标题的方法
修改dlx名称, 修改对话框标题的方法: theDialog->TopBlock()->FindBlock("Dialog")->GetProperties()- ...
- Swift - 告警框(UIAlertView)的用法
1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮 (注:自IOS8起,建议使用UIAlertController) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...
- JQuery EasyUI 对话框的使用方法
下面看一下EasyUI的对话框效果图 js代码: 复制代码代码如下: <script language="javascript" type="text/javasc ...
- Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法(通过COM来改造)
刚有一段时间没做博客了,今天刚好有人问了这个问题,而自己以前也弄过,于是这里有了一篇新的博文. 关于改造WebBrowser控件的一些技巧,大家可以参考MSDN或者蒋晟写的一个东西,里面有讲的很详细的 ...
- Eclipse用法:自动生成get和set方法
方法一 Java的类中,除了常量声明为静态且公有的,一般的对象数据作用域,都是声明为私有的.这样做能保护对象的属性不会被随意改变,调试的时候也会方便很多:在类的公有方法中大一个调用栈就能看到哪里改 ...
- adb环境配置+常用adb命令+Logcat命令的用法+手动进行文件比对的方法+批量挪bug
1. adb环境配置:下载adb环境变量包:打开计算机属性-高级系统设置-环境变量:新建变量adb,值为刚才的环境变量包路径:编辑path值,在最后面加上;%adb%;确定就妥了 2. 常用adb命令 ...
随机推荐
- 判断DataReader中是否有指定列
取出的DataReader如果在读取过程中报没有列的错误可以用这个方法. //调用该方法判断datareader中是否有指定列 public static bool readerExists(IDat ...
- 洛谷 P1508 Likecloud-吃、吃、吃
P1508 Likecloud-吃.吃.吃 题目提供者JosephZheng 标签 动态规划 难度 普及/提高- 题目背景 问世间,青春期为何物? 答曰:"甲亢,甲亢,再甲亢:挨饿,挨饿,再 ...
- Linux 获取文件夹下的所有文件
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4129616.html #include <string> #include &l ...
- winfrom 水晶按钮
闲来无事,从网上找了不少自定义控件,然后整理了一下,做了一个水晶按钮 /// <summary> /// 表示 Windows 的按钮控 /// </summary> [Des ...
- angularJs--$on、$emit和$broadcast的使用
$emit只能向parent controller传递event与data $broadcast只能向child controller传递event与data $on用于接收event与data 例子 ...
- PhpExcel数组输出到Excel浏览器下载
经常是mysql查出二维数组,并且数组的带key也是有意义的,考虑到经常用,就打算弄个函数出来,方便以后用! 相对是规范的数组哈,具体可看下$data数组: 生成的excel第一行是对应的key: 直 ...
- Mysql 存储过程小例子
创建存储过程: DELIMITER $$ USE `database_name`$$ DROP PROCEDURE IF EXISTS `add_or_update_user`$$ )) BEGIN ...
- nrm —— 快速切换 NPM 源 (附带测速功能)
以前我们介绍过cnpmjs.org和最近推出的淘宝 npm 两个 NPM 镜像.除此之外,还有一些国外的 NPM 镜像.不同地区访问不同的镜像速度可能有差异,然后各个镜像各自都可能有少数包暂时没有同步 ...
- iphone开发第一个UI应用程序QQ
#import <UIKit/UIKit.h> @interface HViewController : UIViewController @property (retain, nonat ...
- K最近邻算法
K最近邻(K-Nearest-Neighbour,KNN)算法是机器学习里简单易掌握的一个算法.通过你的邻居判断你的类型,“近朱者赤,近墨者黑”表达了K近邻的算法思想. 一.算法描述: 1.1 KNN ...