不推荐使用UIAlertView:首先在iOS 9.0中弃用

时间:2016-01-06 21:13:20

标签: ios xcode uialertview viewcontroller

我一直在Xcode上遇到错误,我该如何帮助?

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

这里我得到'presentModalViewController:animated'不推荐使用。首先在IOS 6.0中弃用。

-(IBAction)SetMap:(id)sender {

我不推荐使用'UIAlertView':在iOS 9.0中首先弃用 - 不推荐使用UIAlertView。改为使用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。

}

在大括号后我得到'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:'不推荐使用:首先在iOS 6.0中弃用。

1 个答案:

答案 0 :(得分:5)

您收到这些警告/错误,因为这些方法已从代码库中删除。我猜你正在尝试跟上一个旧教程。

您还应该发布更多代码。你告诉我们的不是你的警告/错误所在。

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];
相关问题