UIAlertController 文本输入框使用

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请输入新标题" message:nil preferredStyle:UIAlertControllerStyleAlert];
    //增加确定按钮
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
        //获取第1个输入框;
        UITextField *titleTextField = alertController.textFields.firstObject;
        NSLog(@"%@", titleTextField.text);
    }]];
    //增加取消按钮;
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    //定义第一个输入框;
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        //textField.placeholder = @"请输入标题";
    }];
    [self presentViewController:alertController animated:true completion:nil];

你可能感兴趣的:(UIAlertController 文本输入框使用)