xcode iOS 6 回退到 iOS 5 中已弃用的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12682768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:51:07  来源:igfitidea点击:

Deprecated code in iOS 6 fallback to iOS 5

objective-cxcodeios5ios6fallback

提问by roymckrank

I have this custom back button:

我有这个自定义后退按钮:

- (IBAction)backToMenu:(id)sender {

[self.presentingViewController dismissModalViewControllerAnimated:YES]; 

}

Testing my app in the iOS 6 simulator says dismissModalViewControllerAnimated is deprecated, and I must use dismissViewControllerAnimated instead, so, how I can use the iOS 6 code and fallback to iOS 5

在 iOS 6 模拟器中测试我的应用程序说不推荐使用dismissModalViewControllerAnimated,我必须改用dismissViewControllerAnimated,所以,我如何使用iOS 6 代码并回退到iOS 5

I have tried this:

我试过这个:

if([self respondsToSelector:@selector(presentingViewController:animated:completion:)])
    [self.presentingViewController dismissViewControllerAnimated:(YES) completion:nil];
else if([self respondsToSelector:@selector(presentingViewController:animated:)])
    [self.presentingViewController dismissModalViewControllerAnimated:YES];
else
    NSLog(@"Oooops, what system is this ?!!! - should never see this !");

But without results, I'm seeing the NSLog and no view is dismissed, any hints?

但是没有结果,我看到的是 NSLog 并且没有视图被驳回,有什么提示吗?

Thank you in advance.

先感谢您。

回答by Tim

The selectors you're testing for aren't the same as the selectors you're calling. Try the following:

您正在测试的选择器与您正在调用的选择器不同。请尝试以下操作:

if([self.presentingViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
    [self.presentingViewController dismissViewControllerAnimated:(YES) completion:nil];
else if([self.presentingViewController respondsToSelector:@selector(dismissModalViewControllerAnimated:)])
    [self.presentingViewController dismissModalViewControllerAnimated:YES];
else
    NSLog(@"Oooops, what system is this ?!!! - should never see this !");

The important difference is that the object you're calling- self.presentingViewController, in this case - is different from the method you're calling on that object. We call the latter a selector, and that's the bit you want to put inside the @selector()wrapper.

重要的区别在于您正在调用对象-self.presentingViewController在这种情况下 - 与您在该对象上调用方法不同。我们称后者为选择器,这就是您想要放入@selector()包装器的部分。

回答by Nithinbemitk

Use [self dismissViewControllerAnimated:YES completion:Nil]; for iOS 6

使用 [self deniedViewControllerAnimated:YES 完成:Nil]; 适用于 iOS 6