roy*_*ank 0 xcode fallback objective-c ios5 ios6
我有这个自定义后退按钮:
- (IBAction)backToMenu:(id)sender {
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
在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 !");
Run Code Online (Sandbox Code Playgroud)
但是没有结果,我看到了NSLog并且没有任何视图被解雇,任何提示?
先感谢您.
您正在测试的选择器与您调用的选择器不同.请尝试以下方法:
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 !");
Run Code Online (Sandbox Code Playgroud)
最重要的区别是,你打电话的对象 - self.presentingViewController在这种情况下-从不同的你是调用对象的方法.我们称后者为选择器,这就是你想要放入@selector()包装器的位.
| 归档时间: |
|
| 查看次数: |
5137 次 |
| 最近记录: |