我想在ios 8的alert 视图中添加文本输入.

推荐答案

截图

密码

 UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Login"
                                                                                  message: @"Input username and password"
                                                                              preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"name";
        textField.textColor = [UIColor blueColor];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.borderStyle = UITextBorderStyleRoundedRect;
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"password";
        textField.textColor = [UIColor blueColor];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.borderStyle = UITextBorderStyleRoundedRect;
        textField.secureTextEntry = YES;
    }];
    [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSArray * textfields = alertController.textFields;
        UITextField * namefield = textfields[0];
        UITextField * passwordfiled = textfields[1];
        NSLog(@"%@:%@",namefield.text,passwordfiled.text);

    }]];
    [self presentViewController:alertController animated:YES completion:nil];

Objective-c相关问答推荐

Objective-C 中的实例变量是否默认设置为 nil?

从 C# 到 Objective C 会有多大的飞跃

具有动态高度的子视图的自动布局 UIScrollView

将 CSS 插入 UIWebView / WKWebView 中加载的 HTML

UIRefreshControl iOS 6 xcode

ARC的正确桥接?

如何在另一个视图中获取视图的框架?

未找到 RKObjectMapping.h

iOS:如何将 UIViewAnimationCurve 转换为 UIViewAnimationOptions?

如何将小时数添加到 NSDate?

当用户点击文本字段外的其他区域时如何关闭键盘?

如何在 ios 8 的 alertview 中添加文本输入?

如何推送两个视图控制器但只为第二个设置动画过渡?

IOHIDFamily 的神秘控制台错误

AVAssetImageGenerator 提供旋转的图像

[NSMutableArray array] 与 [[NSMutableArray alloc] init] 之间的区别

Objective-c 协议前向声明

command/usr/bin/codedesign 失败,退出代码 1-代码符号错误

如何将 tintColor 应用于 UIImage?

如何更新 Core Data 中的现有对象?