IOS UIAlertView(警告框)方法总结
转自:my.oschina.net/u/2340880/blog/408873?p=1
IOS中UIAlertView(警告框)常用方法总结
一、初始化方法
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;
这个方法通过设置一个标题,内容,代理和一些按钮的标题创建警告框,代码示例如下:
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"我的警告框" message:@"这是一个警告框" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
效果如下:

注意:如果按钮数超过两个,将会创建成如下样子:

如果按钮数量超出屏幕显示范围,则会创建类似tableView的效果。
二、属性与方法解析
标题属性
@property(nonatomic,copy) NSString *title;
内容属性
@property(nonatomic,copy) NSString *message;
添加一个按钮,返回的是此按钮的索引值
- (NSInteger)addButtonWithTitle:(NSString *)title;
返回根据按钮索引按钮标题
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
获取按钮数量
@property(nonatomic,readonly) NSInteger numberOfButtons;
设置将某一个按钮设置为取消按钮
@property(nonatomic) NSInteger cancelButtonIndex;
返回其他类型按钮第一个的索引值
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex;
警告框是否可见
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
显现警告框
- (void)show;
代码模拟点击按钮消失触发方法
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
设置警告框风格
@property(nonatomic,assign) UIAlertViewStyle alertViewStyle;
风格的枚举如下
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,//默认风格
UIAlertViewStyleSecureTextInput,//密码输入框风格
UIAlertViewStylePlainTextInput,//普通输入框风格
UIAlertViewStyleLoginAndPasswordInput//账号密码框风格
};
这个方法设置文本输入框的索引
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex;
三、UIAlertViewDelegate中的方法
点击按钮时触发的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
将要展现警告框时触发的方法
- (void)willPresentAlertView:(UIAlertView *)alertView;
已经展现警告框时触发的方法
- (void)didPresentAlertView:(UIAlertView *)alertView;
警告框将要消失时触发的方法
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;
警告框已经消失时触发的方法
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
设置是否允许第一个按钮不是取消按钮
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;
IOS UIAlertView(警告框)方法总结的更多相关文章
- IOS中UIAlertView(警告框)常用方法总结
一.初始化方法 - (instancetype)initWithTitle:(NSString *)title message:(NSString*)message delegate:(id /*&l ...
- Jetbrains 2018 等系列软件激活破解除去黄色警告框方法(含多个平台)
现在以IDEA 2018软件在windows为例进行讲解破解方法,其它软件及其在不同平台的破解方法原理 大同小异,有需要的有兴趣的可以尝试一下. 最近更新了Intellij IDEA到2018.1.5 ...
- iOS警告框和操作表
应用如何与用户交流呢? 警告框(AlertView)和操作表(ActionSheet)就是为此而设计的. 本文案例的原型草图如图3-48所示,其中有两个按钮“Test警告框”和“Test操作表”,点击 ...
- 第二百四十六节,Bootstrap弹出框和警告框插件
Bootstrap弹出框和警告框插件 学习要点: 1.弹出框 2.警告框 本节课我们主要学习一下 Bootstrap 中的弹出框和警告框插件. 一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的 ...
- IOS 警告框 (UIAlertView)的使用方法
1.普通警告框 IOS的SDK中提供了一个方便的类库UIAlertView,配合着不同参数来使用此类可以做出大多数的警告框,如下代码是IOS最简单的警告框. UIAlertView *alert = ...
- iOS:提示框(警告框)控件UIAlertView的详解
提示框(警告框)控件:UIAlertView 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能. 类型:typedef NS_ENUM(NSInte ...
- iOS:提示框(警告框)控件UIActionSheet的详解
提示框(警告框)控件2:UIActionSheet 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.它与导航栏类似,它继承自UIView. 风格类型: ...
- selenium+webdriver+python 中警告框的处理方法
在自动化测试过程中,经常会遇到弹出警告框的情况,如图所示: 在 WebDriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体做法是使用 ...
- UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]
//// ViewController.h// UIAlertViewAndUIActionSheet//// Created by hehe on 15/9/21.// Copyright ...
随机推荐
- 小白学 Python(21):生成器基础
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...
- VMware下Centos7-Minimal上网配置
1.Centos7下载 http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso 2.推荐 ...
- 使用Bootstrap制作简单的旅游主页
页面效果 代码: 需要导入bootstrapt文件,解压至项目中. 下载地址:https://v3.bootcss.com/getting-started/#download <!DOCTYPE ...
- CGI、FastCGI、CLI、Apache、ISAPI之PHP运行环境对比
1.运行模式 关于PHP目前比较常见的五大运行模式: 1)CGI(通用网关接口 / Common Gateway Interface) 2)FastCGI(常驻型CGI / Long-Live CGI ...
- java编程思想第四版第十一章习题
第一题 package net.mindview.holding.test1; import java.util.ArrayList; import java.util.List; /** * 沙鼠 ...
- hdu 1233 (prim,最小生成树) 还是畅通工程
还是畅通工程Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- nyoj 55-懒省事的小明(priority_queue)
55-懒省事的小明 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:8 submit:62 题目描述: 小明很想吃果子,正好果园果子熟了. ...
- 逆向libbaiduprotect(三)- 移植python操作dalvik虚拟机c++函数,配合gdb控制程序运行流程
python编译移植到测试机,并且移植ctypes模块.利用ctypes代替c程序,利用dalvik内部c++函数,在运行过程中手动命令操控dalvik虚拟机,并结合gdb进行调试.绕过zygote和 ...
- HashSet源码学习,基于HashMap实现
HashSet源码学习 一).Set集合的主要使用类 1). HashSet 基于对HashMap的封装 2). LinkedHashSet 基于对LinkedHashSet的封装 3). TreeS ...
- caffe网络在多线程中无法使用GPU的解决方案 | cpp caffe net run in multiple threads
本文首发于个人博客https://kezunlin.me/post/8d877e63/,欢迎阅读! cpp caffe net run in multiple threads Guide set_mo ...