如下代码,
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"恭喜你答对了" delegate:nil cancelButtonTitle:@"点击取消" otherButtonTitles:nil];
[alertView show];会提示:
把代码修改成:
UIAlertController *aleView=[UIAlertController alertControllerWithTitle:@"提示" message:@"恭喜你答对了" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[aleView addAction:cancel];
[self presentViewController:aleView animated:YES completion:nil];报错消失:
运行后效果如图

本文介绍了从过时的UIAlertView迁移到UIAlertController的过程,展示了如何更新代码以解决UIAlertView在新环境中出现的问题,并给出了正确的UIAlertController使用示例。
965

被折叠的 条评论
为什么被折叠?



