• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
那一季&花开
博客园    首页    新随笔    联系   管理    订阅  订阅

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代理方法
posted @ 2015-08-24 18:44  那一季&花开  阅读(148)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3