- 在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];