举例:

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

转载于:https://www.cnblogs.com/zxykit/p/5197853.html

UIAlertView使用全解相关推荐

  1. 一般将来时语法课教案_「英语语法」一般过去时用法技巧全解

    大家好,我是教课蚪英语的张老师,今天我们来学习英语语法100讲的第一课,一般过去时! 一.首先我们了解一下什么是一般过去时? 英语语法 1. 概念: 描述过去的状态或过去的动作. 在英语中,非现在的以 ...

  2. atca背板_ATCA介绍全解.ppt

    ATCA介绍全解 ATCA - 概述Advanced Telecommunications Computing Architecture 高性能计算机和网络通信设备的要求: 1) 足够强的数据处理能力 ...

  3. 生成对抗网络gan原理_中国首个“芯片大学”即将落地;生成对抗网络(GAN)的数学原理全解...

    开发者社区技术周刊又和大家见面了,萌妹子主播为您带来第三期"开发者技术联播".让我们一起听听,过去一周有哪些值得我们开发者关注的重要新闻吧. 中国首个芯片大学,南京集成电路大学即将 ...

  4. Java IO编程全解(五)——AIO编程

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7794151.html 前面讲到:Java IO编程全解(四)--NIO编程 NIO2.0引入了新的异步通道的 ...

  5. Sql Server函数全解三数据类型转换函数和文本图像函数

    原文:Sql Server函数全解<三>数据类型转换函数和文本图像函数 一:数据类型转换函数 在同时处理不同数据类型的值时,SQL Server一般会自动进行隐士类型转换.对于数据类型相近 ...

  6. html5相关介绍ppt,html5介绍全解.ppt

    html5介绍全解 渐变 (Gradients) 线性渐变: background: linear-gradient(to right, red, orange, yellow, green, blu ...

  7. 语义分割中的深度学习方法全解:从FCN、SegNet到各版本DeepLab

    语义分割中的深度学习方法全解:从FCN.SegNet到各版本DeepLab 原文:https://www.sohu.com/a/155907339_610300 图像语义分割就是机器自动从图像中分割出 ...

  8. 人工操作阶段计算机是如何工作的,第一章计算机基础概述全解.ppt

    第一章计算机基础概述全解 1.2.3 汉字编码 汉字的编码 国标码:中文内码之一,汉字信息交换的标准编码.国标码是不可能在计算机内部直接采用.于是, 汉字的机内码采用变形国标码 . 国标码:作为转换为 ...

  9. python100个必背知识-python编程面试中必考的知识点,数据类型全解,笔记超全面...

    原标题:python编程面试中必考的知识点,数据类型全解,笔记超全面 python作为一门高级编程语言,它的定位是优雅.明确和简单.阅读Python编写的代码感觉像在阅读英语一样,这让使用者可以专注于 ...

  10. python中的format什么意思中文-Python中format()格式输出全解

    格式化输出:format() format():把传统的%替换为{}来实现格式化输出 1.使用位置参数:就是在字符串中把需要输出的变量值用{}来代替,然后用format()来修改使之成为想要的字符串, ...

最新文章

  1. mysql create table()_MySQL Create Table创建表
  2. foreach循环怎么获取全部返回值_jmeter基础逻辑控制器之ForEach控制器
  3. 如何比较传统WAN与SD-WAN?有什么差别? Vecloud微云
  4. 在屏幕上输出你好的python语句是_编程实现:在屏幕上输出中文字符“你好,世界”。(输出结果中不带双引号)_学小易找答案...
  5. 使用maxscale数据库中间件解决读负载均衡
  6. 通过QEMU 和 IDA Pro远程调试设备固件
  7. 决策树c4.5编译,
  8. SpringBoot切换Tomcat容器,SpringBoot使用Jetty容器
  9. sublime快捷键代码对齐_Python配置sublime运行环境
  10. python爬虫验证码的识别_Python爬虫识别验证码
  11. tt服务器系统,tt服务器
  12. android崩溃拦截给出提示显示日志
  13. 样条曲面_用SolidWorks画一个自然、光顺过渡的曲面
  14. java暂停脚本_用Rhino解析Java中的JavaScript:暂停/恢复脚本
  15. JavaScript 对象分类
  16. Java集成建行龙支付接口(详细)
  17. “离职同事在工作群抢红包被踢”:学会退群,是职场人的基本修养
  18. html写小星星,写小星星的句子
  19. vue插件瀑布流vue-masonry(带源码)
  20. Elasticsearch学习笔记:MUST_NOT not working with EXIST in NESTED query

热门文章

  1. php 远程函数,php 远程图片保存到本地的函数类
  2. 终于等到你:国内***团队360Vulcan公布iOS 12.1越狱漏洞细节
  3. 利用 Web Share API 将网页分享到 App(下)
  4. JavaScript数组forEach循环
  5. 这些练习并没有多少用,但舍不得就扔了,作个记录吧。
  6. Java 下一代: Groovy、Scala 和 Clojure
  7. 切换google的公共库缓解网站访问慢的问题
  8. linux 文件与目录操作
  9. About “condition variables”
  10. 一些and知识 和ui