Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用obj-c在UIAlertView中创建文本字段_Ios_Objective C - Fatal编程技术网

Ios 使用obj-c在UIAlertView中创建文本字段

Ios 使用obj-c在UIAlertView中创建文本字段,ios,objective-c,Ios,Objective C,如何将文本字段放入UIAlertView?如何获取用户刚刚在文本字段中输入的字符串的值? 所有这些都带有Objective-C 非常感谢 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional set

如何将文本字段放入UIAlertView?如何获取用户刚刚在文本字段中输入的字符串的值? 所有这些都带有Objective-C

非常感谢

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated{
    [self alert];
}

- (void) alert {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Name"
                                                                                  message: @"Input your new username"
                                                                              preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"username";
    }];
    [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSArray * textfields = alertController.textFields;
        UITextField * usernamefield = textfields[0];
        NSLog(@"%@",usernamefield.text);

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

@end