iOS:小警告⚠️'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

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


解决方法、二

iOS:小警告⚠️'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead_第1张图片
提示框

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' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead)