? 近日在寫一個提示框的時候吃环,發(fā)現(xiàn)蘋果把uialertview禁止了础爬,同時提供了一個新的api UIAlertController索赏,使用起來也挺簡單:
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];
? 第一個方法是配置提示框的標題和顯示信息,以及style,可以選擇sheet或者alert秩冈;第二蚂子、三個方法是設置一個按鈕沃测,用戶點擊了之后alert就會消失,還有一個handler可以接受用戶的點擊然后設置需要的下一步處理