iOS8 UIAlertContorller 的使用代碼

<span style="font-size:18px;">#import "TRViewController.h"

@interface TRViewController ()

@end

@implementation TRViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)creatAlertView:(id)sender {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title" message:@"message here.." preferredStyle:UIAlertControllerStyleAlert];
    //將框中顯示的按鈕獨立成了UIAlertAction類型
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"點擊了取消按鈕");
    }];
    UIAlertAction *otherAction  = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        UITextField *input =(UITextField *)alert.textFields[0];
        NSLog(@"%@",input.text);
    }];
    //將創建的兩個按鈕添加到警告框中
    [alert addAction:cancleAction];
    [alert addAction:otherAction];
    //添加輸入框
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"xxxx";
        textField.secureTextEntry = YES;
    }  ];  //顯示警告框
    [self presentViewController:alert animated:YES completion:nil];
}
</span>

發佈了22 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章