? 近日在寫一個(gè)提示框的時(shí)候,發(fā)現(xiàn)蘋果把uialertview禁止了,同時(shí)提供了一個(gè)新的api UIAlertController,使用起來也挺簡(jiǎn)單:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"輸入記錄表名稱" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
? 第一個(gè)方法是配置提示框的標(biāo)題和顯示信息,以及style,可以選擇sheet或者alert;第二、三個(gè)方法是設(shè)置一個(gè)按鈕,用戶點(diǎn)擊了之后alert就會(huì)消失,還有一個(gè)handler可以接受用戶的點(diǎn)擊然后設(shè)置需要的下一步處理