UIAlert的使用

1 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"密码验证"
 2 
 3                                                     message:@"请输入管理员密码"
 4 
 5                                                    delegate:nil
 6 
 7                                           cancelButtonTitle:@"cancel"
 8 
 9                                           otherButtonTitles:@"OK", nil];
10 
11     //设置代理
12 
13     alert.delegate = self;
14 
15  
16 
17     // 基本输入框,显示实际输入的内容
18 
19     alert.alertViewStyle = UIAlertViewStylePlainTextInput;
20 
21     // 用户名,密码登录框
22 
23     //    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
24 
25     // 密码形式的输入框,输入字符会显示为圆点
26 
27     //    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
28 
29     
30 
31     //设置输入框的键盘类型
32 
33     UITextField *tf = [alert textFieldAtIndex:0];
34 
35     tf.keyboardType = UIKeyboardTypeNumberPad;
36 
37     
38 
39     UITextField *tf2 = nil;
40 
41     if (alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) {
42 
43         // 对于用户名密码类型的弹出框,还可以取另一个输入框
44 
45         tf2 = [alert textFieldAtIndex:1];
46 
47         tf2.keyboardType = UIKeyboardTypeASCIICapable;
48 
49     }
50 
51     
52 
53     // 取得输入的值
54 
55     NSString* text = tf.text;
56 
57     NSLog(@"INPUT:%@", text);
58 
59     if (alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) {
60 
61         // 对于两个输入框的
62 
63         NSString* text2 = tf2.text;
64 
65         NSLog(@"INPUT2:%@", text2);
66 
67     }
68 
69     
70 
71     
72 
73     [alert show];
74 
75   //点击事件调用UIAlert代理方法

转载于:https://www.cnblogs.com/yxt9322yxt/p/4755610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值