'UIAlertView' is deprecated的解决例子

如下代码,

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

报错消失:


运行后效果如图



你可能感兴趣的:(iOS,BUG)