美文网首页iOS开发Xcode编译错误解决
iOS:小警告⚠️'UIAlertView' i

iOS:小警告⚠️'UIAlertView' i

作者: iOS技术小卒 | 来源:发表于2017-04-19 14:52 被阅读94次
    UIAlertView小警告

    【“ 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead”】

    【deprecated:过去的;反对】


    解决方法一:

    UIAlertController是iOS8以后才出现的类,如果你的项目需要兼容iOS7,恐怕你不能使用这个类,否则会崩溃的。你要是觉得黄色的警告看着不爽,可以这样。

    #pragma clang diagnostic push

    #pragma clang diagnostic ignored"-Wdeprecated-declarations"

    //这里是会报警告的代码

    #pragma clang diagnostic pop


    解决方法、二

    提示框

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"保存" message:@"保存文档吗" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancel  =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

    UIAlertAction *sure  =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];

    [alertController addAction:cancel];

    [alertController addAction:sure];

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

    相关文章

      网友评论

        本文标题:iOS:小警告⚠️'UIAlertView' i

        本文链接:https://www.haomeiwen.com/subject/gethzttx.html