UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"請輸入個(gè)人信息" preferredStyle:UIAlertControllerStyleAlert];
//增加確定按鈕;
[alertController addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//獲取第1個(gè)輸入框;
UITextField *userNameTextField = alertController.textFields.firstObject;
//獲取第2個(gè)輸入框;
UITextField *passwordTextField = alertController.textFields.lastObject;
NSLog(@"用戶名 = %@市殷,密碼 = %@",userNameTextField.text,passwordTextField.text);
}]];
//增加取消按鈕秦叛;
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
//定義第一個(gè)輸入框新荤;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"請輸入用戶名";
}];
//定義第二個(gè)輸入框荧嵌;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"請輸入密碼";
}];
[self presentViewController:alertController animated:true completion:nil];
摘自:https://blog.csdn.net/chenyufeng1991/article/details/49537053