iOS 6中不推荐使用的代码回退到iOS 5

时间:2012-10-02 00:00:54

标签: objective-c xcode ios5 ios6 fallback

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

- (IBAction)backToMenu:(id)sender {

[self.presentingViewController dismissModalViewControllerAnimated:YES]; 

}

在iOS 6模拟器中测试我的应用程序说不推荐使用dismissModalViewControllerAnimated,我必须使用dismissViewControllerAnimated,因此,我如何使用iOS 6代码并回退到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并且没有任何视图被驳回,任何提示?

提前谢谢。

2 个答案:

答案 0 :(得分:6)

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

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

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

答案 1 :(得分:5)

使用[self dismissViewControllerAnimated:YES completion:Nil];对于iOS 6