Ios 使用obj-c在UIAlertView中创建文本字段
如何将文本字段放入UIAlertView?如何获取用户刚刚在文本字段中输入的字符串的值? 所有这些都带有Objective-C 非常感谢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
#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