举例:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Default Alert View"message:@"Defalut" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];


标准的双按钮,cancel那个buttonIndex 为0, ok button 的buttonIndex为1

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Default Alert View"message:@"Defalut" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@“ThirdButton”, nil];

和程序里的顺序一样,cancel   ok   thirdButton 的buttonIndex 分别为0 1 2

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Default Alert View"message:@"Defalut" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@“ThirdButton”, nil];

同理,cancel   ok   thirdButton FourthButton的buttonIndex 分别为0 1 2 3

[alertView show];

 

UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
alertView--->这个不用多说了吧
buttonIndex---->从0开始
可以通过if (buttonIndex == 1) { } 这样的来控制点击了某个按钮需要做什么操作
 
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
这个方法在动画结束和视图隐藏之后调用
 
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
这个方法在动画开始和视图隐藏之前调用
 
- (void)alertViewCancel:(UIAlertView *)alertView
在视图将要被取消之前
例如,用户点击了home键
三个函数的调用顺序依次是:
alertViewCancel----》willDismissWithButtonIndex---》didDismissWithButtonIndex
 
- (BOOL)alertViewShouldEnableFirstOtherButton(UIAlertView *)alertView
ios 5+
设置yes / no  将会设置alertView 的第一个otherButton的enable属性
 
- (void)didPresentAlertView:(UIAlertView *)alertView
在视图提交给用户以后调用
 
-  (void)willPresentAlertView:(UIAlertView *)alertView
在视图提交给用户以前调用
 
这六个delegate 方法调用的顺序依次是
alertViewShouldEnableFirstOtherButton---->willPresentAlertView--->didPresentAlertView
---->clickedButtonAtIndex---->(如果会触发视图取消,则会调用alertViewCancel)willDismissWithButtonIndex---->didDismissWithButtonIndex
 
ios4.0以后 alertView不会自动随着程序转向后台而移除
alertView属性
1.alertViewStyle:
UIAlertViewStyleDefault 只弹信息和按钮
UIAlertViewStyleSecureTextInput 有一个textfield加密框
UIAlertViewStylePlainTextInput 有一个不加密的textfield
UIAlertViewStyleLoginAndPasswordInput 有两个textfield,Login和password
 
只要有textfield就可以用textfieldAtIndex来捕获并进行相应的操作例如换键盘类型
 
2.cancelButtonIndex
开始是0,如果没有设置cancel button 则是-1
 
3.delegate
如果没有设置则是nil
 
4.firstOtherButtonIndex
从0开始,如果没设置则是-1,而且没被设置则会被忽略
 
5.message 
消息
 
6.numberOfButtons
只读  alertView中的按钮数量
 
7.title
标题
 
8.visible
只读  如果是yes 表示被显示
 
实例方法
- (NSInteger)addButtonWithTitle:(NSString *)title
返回值是增加的Button的index
 
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
输入buttonIndex 返回button的标题
 
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
程序自动完成点击buttonIndex的button 并dismiss 整个alertView的操作
 
- (id)initWithTitle:(NSString *)title message:(NSString)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitles, ...
这个就不用多说了
 
- (void)show
要显示必须要调用这个alertview才会显示
 
-  (UITextField *)textfieldAtIndex:(NSInteger)textfieldIndex
返回值是textfield
UIAlertViewStyleDefault 没有
UIAlertViewStyleSecureInput textfieldIndex 只有一个为0
UIAlertViewStylePlainInput textfieldIndex 只有一个为0
UIAlertViewStyleLoginAndPasswordInput textfieldIndex有两个 0 1

UIAlertView使用全解的更多相关文章

  1. IOS-UITextField-全解

    IOS-UITextField-全解   //初始化textfield并设置位置及大小   UITextField *text = [[UITextField alloc]initWithFrame: ...

  2. 易全解token获取

    //易全解app             string strClientID = "2016061711434943493606";             string str ...

  3. 什么是JavaScript闭包终极全解之一——基础概念

    本文转自:http://www.cnblogs.com/richaaaard/p/4755021.html 什么是JavaScript闭包终极全解之一——基础概念 “闭包是JavaScript的一大谜 ...

  4. [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解

    UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...

  5. Sql Server函数全解<五>之系统函数

    原文:Sql Server函数全解<五>之系统函数  系统信息包括当前使用的数据库名称,主机名,系统错误消息以及用户名称等内容.使用SQL SERVER中的系统函数可以在需要的时候获取这些 ...

  6. Sql Server函数全解<四>日期和时间函数

    原文:Sql Server函数全解<四>日期和时间函数   日期和时间函数主要用来处理日期和时间值,本篇主要介绍各种日期和时间函数的功能和用法,一般的日期函数除了使用date类型的参数外, ...

  7. 九度oj题目&amp;吉大考研11年机试题全解

    九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码).    http://ac.jobdu.com/problem.php?pid=11 ...

  8. js系列教程2-对象、构造函数、对象属性全解

    全栈工程师开发手册 (作者:栾鹏) 快捷链接: js系列教程1-数组操作全解 js系列教程2-对象和属性全解 js系列教程3-字符串和正则全解 js系列教程4-函数与参数全解 js系列教程5-容器和算 ...

  9. js系列教程1-数组操作全解

    全栈工程师开发手册 (作者:栾鹏) 快捷链接: js系列教程1-数组操作全解 js系列教程2-对象和属性全解 js系列教程3-字符串和正则全解 js系列教程4-函数与参数全解 js系列教程5-容器和算 ...

随机推荐

  1. gulp相关知识(1)

    这是一种简单的工具,非常容易上手而且功能也是多种多样. 例如将整个网站打包下来的时候,看到的js代码总是混乱的,这就是类似于gulp的工具进行了加密,其他的功能还有很多这里就不赘述了. 首先是gulp ...

  2. Lucene中的 Query对象

    "Lucene中的 Query对象": 检 索前,需要对检索字符串进行分析,这是由queryparser来完成的.为了保证查询的正确性,最好用创建索引文件时同样的分析器. quer ...

  3. Tomcat 虚拟目录映射

    最近老是被一个旧Ant工程所困扰,代码版本都改好了测试也通过了,就是打不了war包,一看build.xml 我的天 各种逆天啊....头大.于是乎想起了最基础的tomcat虚拟目录虽是一个很基础的点, ...

  4. cocos2d Android.mk自动添加类

    打开Android.mk修改以下代码: LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Cla ...

  5. JavaScript(四)---- 函数

    函数主要用来封装具体的功能代码. 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 格式: function 函数名(形参列表){         ...

  6. JavaScript window.setTimeout() 的详细用法

    setTimeout (表达式,延时时间)setTimeout(表达式,交互时间) 延时时间/交互时间是以豪秒为单位的(1000ms=1s) setTimeout 在执行时,是在载入后延迟指定时间后, ...

  7. Android, BaseAdapter 处理大数据量时的优化

    Android优化 最常见的就是ListView, Gallery, GridView, ViewPager 的大数据优化  图片优化  访问网络的优化优化的原则: 数据延迟加载  分批加载  本地缓 ...

  8. 使用Word API打开Word文档 ASP.NET编程中常用到的27个函数集

    使用Word API(非Openxml)打开Word文档简单示例(必须安装Word) 首先需要引入参照Microsoft.Office.Interop.Word 代码示例如下: public void ...

  9. 怎样让外界无法改变自定义view的尺寸大小

    重写setFrame和setBounds方法即可. + (instancetype)testView { return [[self alloc] init]; } - (void)setFrame: ...

  10. java调用dll-JNA

    介绍 给大家介绍一个最新的访问本机代码的 Java 框架 —JNA . JNA(Java Native Access) 框架是一个开源的 Java 框架,是 SUN 公司主导开发的,建立在经典的 JN ...