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];