iOS 8.0 之后UIAlertController弹框代替了UIAlertView弹框 和 UIActionSheet下弹框
//初始化一个UIAlertController
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请。。。。。" preferredStyle:UIAlertControllerStyleAlert];
//创建按钮
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//点击按钮的响应事件
NSLog(@"点击按钮的响应事件");
}];
//创建取消按钮
//注意取消按钮只能添加一个
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
NSLog(@"取消");
}];
//创建警告按钮
UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){
NSLog(@"警告");
}];
//添加按钮 将按钮添加到UIAlertController对象上
[alertController addAction:okAction];
[alertController addAction:cancelAction];
[alertController addAction:structlAction];
//只有在alert情况下才可以添加文本框
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
textField.placeholder = @"请输入...";
textField.secureTextEntry = YES;
}];
//取出文本
//UITextField *text = alertController.textFields.firstObject;
//UIAlertAction *action = alertController.actions.firstObject;
//模态弹出提示框 相当于UIAlertView show 的方法
[self presentViewController:alertController animated:YES completion:nil];