【转】 UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
原文网址:http://blog.csdn.net/enuola/article/details/7900346
首先,视图控制器必须得实现协议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对对话框的事件处理方法
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: ViewController. ...
- (转) UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: #import <UIK ...
- Swift - 告警框(UIAlertView)的用法
1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮 (注:自IOS8起,建议使用UIAlertController) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...
- adb环境配置+常用adb命令+Logcat命令的用法+手动进行文件比对的方法+批量挪bug
1. adb环境配置:下载adb环境变量包:打开计算机属性-高级系统设置-环境变量:新建变量adb,值为刚才的环境变量包路径:编辑path值,在最后面加上;%adb%;确定就妥了 2. 常用adb命令 ...
- 用法:node模块都具备的方法(exports、module、require、__filename、__dirname)
凡是玩弄nodejs的人,都明白,每一个模块都有exports.module.require.__filename.__dirname的方法 清楚了解方法的用法后,玩转node就等于清楚了日常讲话的内 ...
- 【Python—字典的用法】创建字典的3种方法
#创建一个空字典 empty_dict = dict() print(empty_dict) #用**kwargs可变参数传入关键字创建字典 a = dict(one=1,two=2,three=3) ...
- Eclipse用法:自动生成get和set方法
方法一 Java的类中,除了常量声明为静态且公有的,一般的对象数据作用域,都是声明为私有的.这样做能保护对象的属性不会被随意改变,调试的时候也会方便很多:在类的公有方法中大一个调用栈就能看到哪里改 ...
- C#委托的用法 在C#中我想在一个方法中调用另一个按钮的事件,怎样来实现?
最开始我也不清楚,后来我是这样想了. 1.事件和委托不是一个概念,你如果是调用control的事件,可以直接在其对应的事件eventhandler上attach自己的事件方法就好了如:this.But ...
- 如何使用npm的部分用法以及npm被墙的解决方法
我们要明白我们使用的npm就是node中自带的包(模块)管理工具:借助NPM可以帮助我们快速安和管理依赖包,使Node与第三方模块之间形成了一个良好的生态系统. 我们可以直接输入npm,查看帮助引导: ...
随机推荐
- Windows 进程通信 之 DDE技术
DDE (Dynamic Data Exchange,DDE)动态数据交换,是一种进程间通信机制,它最早是随着Windows由微软提出的.当前大部分软件仍旧支持DDE,但最近十年里微软已经停止发展DD ...
- CentOS 6.6安装LAMP和Subversion服务器
目标:在CentOS 6.6上安装LAMP,并安装最新版1.8.*的Subversion服务器,和Subversion权限管理前端iF.svnadmin. 安装步骤: 安装新一些版本LAMP步骤 1. ...
- linux配置mysql,tomcat命令vi
[root@yangchehome bin]# ./mysqld_safe -user=mysql & [1] 17135 [root@yangchehome bin]# 140316 16: ...
- EF提供的三种查询方式
這邊簡單介紹一下,ADO.Net Entity Framework 提供的三種查詢方式, Linq to Entities Query Builder Mothed Entity SQL Langua ...
- 一个Java程序员应该掌握的10项技能
1.语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知道任何修正. 2.命令:必须熟悉JDK带的一些常用命令及其常用选项,命令至少需要熟悉:a ...
- Ubuntu环境下Hadoop1.2.1, HBase0.94.25, nutch2.2.1各个配置文件一览
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
- Android学习及开发随记1:Android Studio安装配置
1.本系列仅为个人使用,概不负责.随着时间推移,部分内容可能因为软件更新而出现不能对应的情况. 本文的配置情况,仅针对Android Studio v1.1.0 windows版本 全新安装. Goo ...
- spring aop通过joinpoint传递参数
三.总结. 我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得. 三.总结. 我们可以通过Advice中添加一个JoinPoint ...
- IP地址字符串与BigInteger的转换
/** * Copyright (c) 2010, 新浪网支付中心 * All rights reserved. * * Java IP地址字符串与BigInteger的转换, * ...
- NSDictionary 初始化
NSDictionary *dic1=[NSDictionary dictionaryWithObject:@"1" forKey:@"a"]; ...