iOS 6中不推荐使用的代码回退到iOS 5 [英] Deprecated code in iOS 6 fallback to iOS 5

查看:128
本文介绍了iOS 6中不推荐使用的代码回退到iOS 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this custom back button:

- (IBAction)backToMenu:(id)sender {

[self.presentingViewController dismissModalViewControllerAnimated:YES]; 

}

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

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

我试过这个:

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 !");

但是没有结果,我看到了NSLog并且没有任何视图被解雇,任何提示?

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

提前谢谢。

推荐答案

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

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 !");

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

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.

这篇关于iOS 6中不推荐使用的代码回退到iOS 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆