最近在学习ios开发,学习的书籍《ios7 Pragramming cookbook》,做笔记的目的以后方便查看。笔记形式是小例子,将书上的例子书写完整。

UIAlertViewClass 的使用场景

  1,向用户以一个警告的形式显示信息。

   2,让用户确认一些动作

   3,让用户输入用户名和密码

   4,让用户输入一些文本,这些文本在程序被使用

例1   实现简单显示一些警告信息

新建一个 Single View Application 简单工程,工程名字维AlterView,扩展前缀CB

 

代码如下:

#import "CBViewController.h"

@interface CBViewController ()
@end @implementation CBViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIAlertView *alterView = [[UIAlertView alloc]
initWithTitle:@"学些MAC/IOS开发"
message:@"一个UIAlterView的例子"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alterView show] ;
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

运行结果示意图

例2  让用户输入账号和密码 ,log输出账号和密码

要获得用户点击的是那个按钮可以在 代码实现 UIAlertViewDelegate 代理中下面的方法

// Called when a button is clicked. The view will be automatically dismissed after this call returns

// 用于点击按钮是被调用,返回被调用button的索引

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

#import "CBViewController.h"

@interface CBViewController ()<UIAlertViewDelegate> //添加代理

@end

@implementation CBViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. UIAlertView *alterView = [[UIAlertView alloc]
initWithTitle:@"学些MAC/IOS开发"
message:@"请输入你的账号和密码"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alterView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput] ; UITextField *user = [alterView textFieldAtIndex: ] ;
user.keyboardType = UIKeyboardTypeAlphabet ; //设置弹出的键盘样式 UITextField *pass = [alterView textFieldAtIndex:] ;
pass.keyboardType = UIKeyboardTypeDefault ; [alterView show] ;
}

////实现代理协议的方法
//// 用于点击按钮是被调用,返回被调用button的索引
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//通过返回button索引 得到点击按钮的现实字符串
NSString *buttonName = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonName isEqualToString:@"确定" ]) {
UITextField *user = [alertView textFieldAtIndex:] ;
UITextField *pass = [alertView textFieldAtIndex:] ;
NSLog(@"确定 账号=%@ 密码=%@", user.text, pass.text) ;
}
else if ([buttonName isEqualToString:@"取消"])
{
NSLog(@"取消");
}
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

输出结果

2014-07-09 15:27:05.980 AlertView[8406:60b] 确定账号=goipc 密码=123456

2014-07-09 15:39:31.938 AlertView[8429:60b] 取消

运行的效果图

ios/mac/COCOA系列 -- UIALertVIew 学习笔记的更多相关文章

  1. java8 学习系列--NIO学习笔记

    近期有点时间,决定学习下java8相关的内容: 当然了不止java8中新增的功能点,整个JDK都需要自己研究的,不过这是个漫长的过程吧,以自己的惰性来看: 不过开发中不是有时候讲究模块化开发么,那么我 ...

  2. contiki-main.c 中的process系列函数学习笔记 <contiki学习笔记之六>

    说明:本文依然依赖于 contiki/platform/native/contiki-main.c 文件. ---------------------------------------------- ...

  3. 【iOS】我的Objective-C学习笔记

    1.代码中增加标记 #pragma mark - #pragma mark 2.点语法 Person *p = [Person new]; // 点语法的本质还是方法调用 p.age = 10; // ...

  4. 《慕客网:IOS-动画入门》学习笔记

    新建Cocoa Touch Class,语言是swift 然后继续为界面添加一个普通的View Controller,并且添加前面视图的静态table的转向剪头指向这个View Controller, ...

  5. iOS多线程之GCD学习笔记

    什么是GCD 1.全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 2.纯C语言,提供了非常多强大的函数 GCD的优势 GCD是苹果公司为多核的并行运算提出的解决方案 G ...

  6. 干货 | Python进阶系列之学习笔记(二)

    目录 对象 字符串 一.对象 (1)什么是对象 在python中一切都是对象,每个对象都有三个属性分别是,(id)身份,就是在内存中的地址,类型(type),是int.字符.字典(dic).列表(li ...

  7. ios 控件代码transform学习笔记

    1.图片设置(平移,缩放,旋转) 创建一个transform属性 //按钮点击时,只能执行一次向上旋转 //派 M_PI_4 45度旋转 . CGAffineTransform transforms= ...

  8. Cocoa Foundation框架学习笔记 - NSCalendar

    + (void)beginTest { /* FOUNDATION_EXPORT NSString * const NSGregorianCalendar; //公历(常用) FOUNDATION_E ...

  9. smartcar 系列机器人学习笔记1

    总体框架: 1,感知一个相机,一个雷达,一个odom(非必须:一个imu)功能:车道线检测,红绿灯检测,障碍物检测 2,决策规划 功能:一次规划,(避障即:二次规划) 3,控制执行 功能:速度控制,角 ...

随机推荐

  1. hdu-5681 zxa and wifi(dp)

    题目链接: zxa and wifi Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  2. Wonderful Sentense

    1.Sorry if I might sound arrogant or offensive. 2.Any further question? 3.How dare you! 4.Try it if ...

  3. NodeJS学习之异步编程

    NodeJS -- 异步编程 NodeJS最大的卖点--事件机制和异步IO,对开发者并不透明 代码设计模式 异步编程有很多特有的代码设计模式,为了实现同样的功能,使用同步方式和异步方式编写代码会有很大 ...

  4. ORACLE之表

    本文章中的表在以后的例子中会用到. 首先有t_fn_person和t_fn_dept表. ) primary key not null, person_code ) not null, person_ ...

  5. Android 手势滑动,多点触摸放大缩小图片

    效果展示: 基本思路: <1>首先写一个图片控制类ImageControl,实现对图片控制的的基本操作,我们的图片控制类ImageControl是继承自ImageView自定义的视图: & ...

  6. 十、Notepad++正则表达式使用

    推荐个正则表达式在线测试的工具http://ccmpp.com/Regex/ Notepad++正则表达式使用 2011-01-06 10:01:35| 分类: 文档 | 标签:正则表达式 替换 no ...

  7. JavaScript之放大镜效果2

    在放大图片效果的同时,我们怎么原图和放大窗体增加间隔呢? 我们只需应用一个table就行了: 源码上: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML ...

  8. apache Internal Server Error 的几个问题

    Internal Server Error The server encountered an internal error or misconfiguration and was unable to ...

  9. UILabel 整理

      UILabel 多行文字自动换行 (自动折行) 1.UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 3 ...

  10. php面向对象的特性:OOP的封装

    字段的作用域: 1.public 公共的(类外可以访问) 2.private 私有的(只能类内访问) 3.protected 受保护的(类内和子类可以访问,类外无法访问) /*通过公共的方法来访问私有 ...