IOS知识整理

[转]iOS8之后弃用UIAlertView,改用UIAlert

2015-12-25  本文已影响5493人  iOS_愛OS

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之后用起来顺手多了!!!!

上一篇 下一篇

猜你喜欢

热点阅读