UIAlertView 已弃用:首先在 iOS 9.0 中弃用

UIAlertView is deprecated: first deprecated in iOS 9.0

我在 Xcode 上不断收到错误消息,我该如何解决这个问题?

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

这里我得到 'presentModalViewController:animated' 已弃用。首先在 IOS 6.0.

中弃用
-(IBAction)SetMap:(id)sender {

这里我得到 'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用 - UIAlertView 已弃用。改用 UIAlertController 和 preferredStyle UIAlertControllerStyleAlert。

}

在大括号之后我得到 'dismissModalViewControllerAnimated:' 已弃用:首先在 iOS 6.0.

中弃用
- (IBAction)Aktiekurs:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.euroinvestor.dk/boerser/nasdaq-omx-copenhagen/novozymes-b-a-s/239698"]];
}

最后我得到 'dismissModalViewControllerAnimated:' is deprecated: first deprecated in iOS 6.0.

您得到这些 warnings/errors 是因为这些方法已从代码库中删除。我猜您正在尝试按照旧教程进行操作。

您还应该 post 更多代码。你给我们看的不是你 warnings/errors 所在的地方。

对于 dismissModalViewControllerAnimated,请改用它。

[self dismissViewControllerAnimated:YES completion:nil];

presentModalViewController:animated 使用这个。

[self presentViewController:newController animated:YES completion:nil];

最后,对于您的 UIAlertView,您现在应该使用 UIAlertController:

UIAlertController *alertController = [UIAlertController
                              alertControllerWithTitle:@"title"
                              message:@"some message"
                              preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                      style:UIAlertActionStyleCancel
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"Cancel action");
                    }];

UIAlertAction *okAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                      style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"OK action");
                    }];

[alertController addAction:cancelAction];
[alertController addAction:okAction];

[self presentViewController:alertController animated:YES completion:nil];