[轉]iOS8之后棄用UIAlertView,改用UIAlertController的詳細說明

  • 在iOS8之后UIAlertView、UIActionSheet (以及它們各自的 delegate protocols)已經被棄用,在你的代碼中按住QQ圖片20141219102558.png點擊 UIAlertView 或者 UIActionSheet,你就會看到最上面的注釋:

NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead") __TVOS_PROHIBITED

NS_CLASS_DEPRECATED_IOS(2_0, 8_3, "UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead") __TVOS_PROHIBITED

本文章的主題就是 UIAlertController,向大家展示如何替換舊的 Alert,以及這些操作方法的高級擴展。

更詳細的內容參考:http://www.cocoachina.com/ios/20141219/10701.html

    // 創建

    UIAlertController *alertview=[UIAlertController alertControllerWithTitle:@"提示" message:@"Successful" preferredStyle:UIAlertControllerStyleAlert];
    // UIAlertControllerStyleActionSheet 是顯示在屏幕底部
    // UIAlertControllerStyleAlert 是顯示在中間
    
    // 設置按鈕
    UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *defult = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];
    //UIAlertAction *destructive = [UIAlertAction actionWithTitle:@"destructive" style:UIAlertActionStyleDestructive handler:nil];
    [alertview addAction:cancel];
    [alertview addAction:defult];
    //[alertview addAction:destructive];
    
     //顯示(AppDelegate.h里使用self.window.rootViewController代替self)

    [self presentViewController:alertview animated:YES completion:nil];

    //[self.window.rootViewController presentViewController:alertview animated:YES completion:nil];

感覺替換了UIAlertController之后用起來順手多了!!!!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容