IOS9 彈出視圖(AlertView,ActionSheet)合併爲一個
一個UIAlertController解決了,兩種彈出視圖,比以往更簡單,更方便。
UIAlertController,大家一看就會明白,是講一個彈出View,改成了,彈出視圖控制器。不管怎麼寫,至少就應該很明白,怎麼展示了。跟跳轉展示界面一樣。IOS9展示彈出視圖,也是用跳轉的語句
不說那麼多了 ,直接上代碼吧。
/*IOS9 下的提示框*/
//初始化提示框;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"確定要退出登錄嗎?" preferredStyle: UIAlertControllerStyleAlert];
/*preferredStyle: 這個有兩種狀態,供大家選擇,當前我提供的是IOS9之前的AlertView樣式。
UIAlertControllerStyleActionSheet —-ActionSheet
UIAlertControllerStyleAlert — AlertView
*/
———-這裏需要幾個按鈕,就添加幾個事件即可
[alert addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//點擊按鈕的響應事件;
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//點擊按鈕的響應事件;
}]];
———-這裏需要幾個按鈕,就添加幾個事件即可
//彈出提示框;
[self presentViewController:alert animated:true completion:nil];