Deprecated code in iOS 6 fallback to iOS 5

前端 未结 2 560
走了就别回头了
走了就别回头了 2021-01-07 13:36

I have this custom back button:

- (IBAction)backToMenu:(id)sender {

[self.presentingViewController dismissModalViewControllerAnimated:YES]; 

}
相关标签:
2条回答
  • 2021-01-07 14:16

    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.

    0 讨论(0)
  • 2021-01-07 14:16

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

    0 讨论(0)
提交回复
热议问题