iOS学习-UIAlertView详解

 1 //
 2 //  ViewController.m
 3 //  UIAlertView详解
 4 //
 5 //  Created by 大欢 on 16/1/25.
 6 //  Copyright © 2016年 bjsxt. All rights reserved.
 7 //
 8 
 9 #import "ViewController.h"
10 
11 @interface ViewController ()
12 
13 - (IBAction)showAlertView:(id)sender;
14 
15 @end
16 
17 @implementation ViewController
18 
19 - (void)viewDidLoad {
20     [super viewDidLoad];
21     
22 }
23 
24 //点击alertView button 触发的方法。
25 //buttonIndex按钮的索引值 cancel的index为0
26 
27 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
28     
29     //获取alertview上的输入文本
30     UITextField * textField1 = [alertView textFieldAtIndex:0];
31     NSLog(@"%@",textField1.text);
32     
33     switch (buttonIndex) {
34         case 0:
35             NSLog(@"取消");
36             break;
37         case 1:
38             NSLog(@"done1");
39             break;
40         case 2:
41             NSLog(@"done2");
42             break;
43         default:
44             break;
45     }
46     
47 }
48 
49 
50 - (IBAction)showAlertView:(id)sender {
51     
52     UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"done", nil];
53     //设置alertView的样式
54     alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
55     //使alertView展示出来
56     [alertView show];
57     
58     //延迟5秒执行dismissAlertView
59 //    [self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:5];
60 }
61 
62 - (void)dismissAlertView:(UIAlertView *)alert {
63     
64     // alertview消失的方法
65     [alert dismissWithClickedButtonIndex:0 animated:YES];
66     
67 }
68 @end

posted @ 2016-01-25 22:12  MrWuYindi  阅读(182)  评论(0编辑  收藏  举报