由于UIAlertView现在已被弃用,我希望使用iOS 8中使用的UIAlertController。是否有一种方法可以在不破坏对iOS 7支持的情况下使用它?是否可以进行某种if条件检查以检查iOS 8,否则为iOS 7支持执行其他操作?
由于UIAlertView现在已被弃用,我希望使用iOS 8中使用的UIAlertController。是否有一种方法可以在不破坏对iOS 7支持的情况下使用它?是否可以进行某种if条件检查以检查iOS 8,否则为iOS 7支持执行其他操作?
尝试下面的代码。它适用于iOS 8及以下版本,运行良好。
if (IS_OS_8_OR_LATER) {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
}];
[alertVC addAction:cancelAction];
[[[[[UIApplication sharedApplication] windows] objectAtIndex:0] rootViewController] presentViewController:alertVC animated:YES completion:^{
}];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
UIAlertView
。这将使您的代码更简单。 - rmaddy