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命令 ...
随机推荐
- C# 线程--第二线程方法
概述 上一章节中和大家分享了线程的基础使用方法.在这一章中来和大家分享线程的一些常用方法. 主要包括:线程阻塞,线程终止,线程锁三方面. Thread 的 Sleep 和 Join 方法 Thread ...
- C++函数模板本质-学习入门
template<typename T> void mySwap(T &a, T &b) { T c; c = a; a = b; b = c; } int main() ...
- [WCF]IIS部署到新系统
最近为以前的一个企业部署软件的时候,接触到WCF,通过博客园大佬的系列文章和一些书籍,基本了解了一些.简单说也算是SOA一种方式,提供某种服务,可以理解为一个类库,供其他项目使用,可以做到业务分离.但 ...
- 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 ...
- 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)
题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...
- java.util.ArrayList源码分析
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess ...
- [DevExpress]GridControl 列头绘制Checkbox
关键代码: /// <summary> /// 为列头绘制CheckBox /// </summary> /// <param name="view" ...
- C#,PHP对应加密函数
require_once "JunDes.php"; $jDes=new JunDes(); echo $jDes->encode('98765'); //echo $jDe ...
- WCF、WebAPI、WCF REST、Web Service之间的区别
在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Services.我分享一下我对 ...
- PHP获取搜索引擎关键字来源(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)
<?php //获取来自搜索引擎入站时的关键词 function get_keyword($url,$kw_start) { $start=stripos($url,$kw_start); $u ...