UIAlertView笔记
链接地址:http://www.cnblogs.com/scandy-yuan/archive/2013/03/11/2954194.html
1. 最简单的用法

UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"这是一个简单的警告框!"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];


2. 为UIAlertView添加多个按钮

UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"请选择一个按钮:"
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:@"按钮一",
@"按钮二",
@"按钮三", nil]
[alert show];


3. 如何判断用户点击的按钮
UIAlertView有一个委托UIAlertViewDelegate ,继承该委托来实现点击事件

头文件:
@interface MyAlertViewViewController : UIViewController<UIAlertViewDelegate> {
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
-(IBAction) buttonPressed;
@end
源文件:
-(IBAction) buttonPressed
{
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"请选择一个按钮:"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"按钮一", @"按钮二", @"按钮三",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString* msg = [[NSString alloc] initWithFormat:@"您按下的第%d个按钮!",buttonIndex];
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:msg
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}

点击“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3

4.修改提示框样式
iOS5中UIAlertView新增了一个属性alertViewStyle,它的类型是UIAlertViewStyle,是一个枚举值:
typedef enum {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
} UIAlertViewStyle;
alertViewStyle属性默认是UIAlertViewStyleDefault。我们可以把它设置为UIAlertViewStylePlainTextInput,那么AlertView就显示为这样:

UIAlertViewStyleSecureTextInput显示为:

UIAlertViewStyleLoginAndPasswordInput为:

当然我们也可以通过创建UITextField来关联这里的输入框并设置键盘响应的样式

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"CD-KEY"
message:@"please enter cd-key:"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField * text1 = [alert textFieldAtIndex:0];
UITextField * text2 = [alert textFieldAtIndex:1];
text1.keyboardType = UIKeyboardTypeNumberPad;
text2.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
[alert show];


UIAlertViewStyleSecureTextInput和UIAlertViewStylePlainTextInput可以通过textFieldIndex为0来获取输入框对象。
UIAlertViewStyleLoginAndPasswordInput可以通过textFieldIndex为0和1分别获取用户名输入框对象和密码输入框对象。
UIAlertView笔记的更多相关文章
- ios/mac/COCOA系列 -- UIALertVIew 学习笔记
最近在学习ios开发,学习的书籍<ios7 Pragramming cookbook>,做笔记的目的以后方便查看.笔记形式是小例子,将书上的例子书写完整. UIAlertViewClass ...
- 【代码笔记】iOS-带输入框的UIAlertView
一,效果图. 二,代码. //点击任何处,弹出输入框 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UIAlertV ...
- RAC学习笔记
RAC学习笔记 ReactiveCocoa(简称为RAC),是由Github开源的一个应用于iOS和OS开发的新框架,Cocoa是苹果整套框架的简称,因此很多苹果框架喜欢以Cocoa结尾. 在学习Re ...
- xmpp整理笔记:发送图片信息和声音信息
图片和音频文件发送的基本思路就是: 先将图片转化成二进制文件,然后将二进制文件进行base64编码,编码后成字符串.在即将发送的message内添加一个子节点,节点的stringValue(节点的值) ...
- xmpp整理笔记:用户网络连接及好友的管理
xmpp中的用户连接模块包括用户的上线与下线信息展现,用户登录,用户的注册: 好友模块包括好友的添加,好友的删除,好友列表的展示. 在xmpp中 负责数据传输的类是xmppStream,开发的过程中, ...
- IOS笔记 1
< ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...
- Effective Objective-C 读书笔记
一本不错的书,给出了52条建议来优化程序的性能,对初学者有不错的指导作用,但是对高级阶段的程序员可能帮助不是很大.这里贴出部分笔记: 第2条: 使用#improt导入头文件会把头文件的内容全部暴露到目 ...
- 【Swift】iOS开发笔记(二)
前言 这个系列主要是一些开发中遇到的坑记录分享,有助于初学者跨过这些坑,攒够 7 条发一篇. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯 ...
- WWDC 2014 Session笔记 - iOS界面开发的大一统
本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 What's New in Cocoa Touch Building Adaptive Apps with UIKit Wh ...
随机推荐
- 第八届河南省赛G.Interference Signal(dp)
G.Interference Signal Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 17 [Submit][Status ...
- Ubuntu 用 pptp 建立 vpn 服务
1.下载pptp sudo apt-get install pptpd 2.配置pptp 须要改动配置下面的文件: pptpd.conf文件:配置链接后的主机ip和能够分配的内存范围 vi /etc/ ...
- iOS中Block介绍(一)基础
ios开发block的使用指南,以及深入理解block的内存管理,也适用于osx开发.讨论范围:block的使用,内存管理,内部实现.不包含的内容:gc arc下的block内存,block在c++中 ...
- 数组有没有 length()这个方法? String 有没有 length()这 个方法?
1.数组中有length属性. 2.String有lenth()方法.
- Vector(容器)
vector(容器)就像数组一样,但比数组强大很多,下面介绍一下vector常用的几种方法: 一.对于vector自身的处理,包括赋初始值,复制等等: vector<int> v1 ; v ...
- mysql 存储过程需要DELIMITER
DELIMITER &&CREATE PROCEDURE syncAdvertiser() BEGIN DECLARE id bigint; DECLARE _cur CURSOR F ...
- html5 geolocation API
清单 1. 检查浏览器支持性if (navigator.geolocation) 清单 2. 单次定位请求 API void getCurrentPosition(updateLocation, op ...
- 关于tomcat的clean
1 添加了一个web项目到tomcat,然后进行clean的时候,根目录实际上是在WebContent下,也就是说存放在WebContent目录下的所有文件在clean的时候才会被添加到tomcat对 ...
- 1.Getting Started
Elasticsearch 是一个高度扩展的开源的全文搜索和分析引擎,它允许你存储,搜索和分析大量的数据和几乎实时. 它通常用于底层的存储.技术,提供应用实现负载的搜索功能和需求. 这里有一些使用的示 ...
- A2W和W2A :很好的多字节和宽字节字符串的转换宏
以前看<Window核心编程>,感觉多字节和宽字节之间还比较麻烦的,至少MultiByteToWideChar函数和WideCharToMultiByte函数有足够多的参数的意义让我们去理 ...