举例:

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. 查看UDP连接情况

    运行界面,输入"CMD"命令; 在命令提示符界面中,输入"netstat -s -p udp"命令,按回车.即可显示本机所有UDP连接情况.

  2. Chapter 1 First Sight——12

    Breakfast with Charlie was a quiet event. 和查理斯吃早饭时一件安静的事情 He wished me good luck at school. I thanke ...

  3. Kth order statistcs

    Selection: selection is a trivial problem if the input numbers are sorted. If we use a sorting algor ...

  4. Ng-model undefined in the controller

    这个问题是我最近在项目中碰到的,暂时没找到原因,找到一个解决方法,还多请大神指教,在Stack Overflow找到解决方法: I am having some "problems" ...

  5. 数值标记问题 离线+树状数组 HDU 3938 + HDU 3333

    HDU 3938 题目大意:给你一个长度为n的数组a,定义区间[l,r]的val为区间内所有不同的数值之和.现在有m个询问,每次询问一个区间,问区间的val是多少. 思路:将所有的询问按照右端点排序. ...

  6. 检查本功能是否在Excel中运行

    BOOL g_bParentIsNotEXCEL_EXE = FALSE; BOOL isNotEXCEL_EXE( DWORD dwProcessID ) { HANDLE hProcessSnap ...

  7. java打jar包

    一.打包jar文件 1      如果是class文件     jar cvf myjar.jar Foo.class Bar.class 如果是包     jar cvf myjar.jar pac ...

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

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

  9. 黄聪:基于Asp.net的CMS系统We7架设实验(环境WIN7,SQL2005,.NET3.5)(初学者参考贴)

    http://www.cnblogs.com/huangcong/archive/2010/03/30/1700348.html

  10. angula组件-通过键盘实现多选(原创)

    在刚刚结束的angular交易系统项目中有几个需求是让我感觉要花点时间的 如何更优雅的使用angular-bootstrap 的 Modal框. 通过键盘实现ctrl多选,shfit批量选的功能. 如 ...