当前位置: 首页 > news >繁体>UIAlertView使用全解

UIAlertView使用全解

举例:

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

UIAlertView使用全解
标准的双按钮,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];
UIAlertView使用全解
和程序里的顺序一样,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];
UIAlertView使用全解

同理,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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:https://dhexx.cn/news/show-19105.html

如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网进行投诉反馈,一经查实,立即删除!


相关文章:

  • K-special Tables
  • 不能对bug视而不见
  • Seven Kinds of Testers - 七种类型的测试
  • CAS(Compare and Swap)理解
  • IOS开发者证书申请及应用上线发布详解(2014版)
  • spark分片个数的确定及Spark内存错误(GC error)的迂回解决方式
  • 在lua中优雅的操作日期和时间
  • JAVA语言基础——类型转换
  • 关于在for循环中绑定事件打印变量i是最后一次。
  • TFS
  • arguments,caller,callee之理解
  • leetcode 31. Next Permutation(字典序的下一个)
  • Java专项面试训练(一)
  • iOS_SN_深浅拷贝( 百度的)_转载
  • 串-第4章-《数据结构题集》答案解析-严蔚敏吴伟民版
  • js判断IE浏览器的方法
  • thinkphp路径引用问题
  • mysql官网下载页面
  • Galera集群server.cnf参数调整--前言
  • 手机交互应用服务(邮件)
  • iOS开发--Swift RAC响应式编程初探
  • 阅读计划及浅读问题
  • 快速阅读《构建之法》——构建之法阅读笔记01
  • Codeforces Beta Round #1 B. Spreadsheets 模拟
  • 线段树——I hate it
  • 苹果有益让老iPhone变慢以迫使消费者购买新一代的iPhone?
  • 编程时的细节
  • Mac上编译C++报错
  • HeadFirst设计模式之命令模式
  • NodeJs之npm
  • 字符串交错组成--很优美的递归算法
  • win32收不到F10按键消息解决的方法
  • 浏览器是否支持Html5
  • C#扩展方法的理解 (转)
  • 内存溢出解决方案
  • [leetcode] @python 113. Path Sum II
  • 函数的汇总
  • MVC 图片预览
  • 第三章 Docker 入门
  • JavaScript系列:模块化与链式编程
  • 误差处理相关
  • 数据库 char nchar varchar nvarchar 区别
  • 浮动元素float
  • 用三方做的豆瓣电影页面
  • swift中闭包的循环引用
  • 今天中午还收到了,一条诈骗短信,说是中奖了
  • 第三周的学习进度情况
  • 20145302张薇《Java程序设计》第三周学习总结
  • [na]802.1x协议无线认证协议dot1x有线认证实验
  • Java之多线程断点下载的实现