dismissModalViewControllerAnimated crashing on iOS

2019-08-25 01:30发布

问题:

I am facing a crash on iOS 6.0. I have a view controller from which I present a navigation view controller modally and then from the navigation stack I present another view controller modally and finally to dismiss the whole modal stack I pass the following message to my first view controller from where I showed the navigation controller.

Now this works fine on iOS below 6.0. How should I handle this?

[self dismissModalViewControllerAnimated:YES];

回答1:

I had this similar crash as well and one of the things helped me solve it was adding:

vc.modalPresentationStyle = UIModalPresentationCurrentContext;



回答2:

maybe because dismissModalViewController is deprecated in iOS6? Try

[self dismissViewControllerAnimated:YES completion:nil];


回答3:

EDIT: Lets say you add a method to appDelegate called 'makeMeNumberOne:(UIViewController *)vc': (I know you use the 'modal' versions, they are deprecated in iOS6, switch to 'presented' variants) . Also I assume you can find the navigationController, if this is a problem add a comment I'll further expand this, and assume you are using ARC.)

  • the parameter you have is a strong reference, it holds the current presented viewController, lets call it pvc

  • ask the navigationController for its viewControllers, and get the last one

  • as a debugging tool, verify that this vc has a non-nil presentedViewController property

  • message the last view controller above:

    [lastOne dismissViewControllerAnimated:NO completion:^{ [navigationController.viewControllers = @[pvc]; }];