2

I am facing a crash on following statement in IOS 5. This seems to work in other IOS versions. The scenario is that I am presenting a view as a modal from a viewController and then on tap on cancel button I call the below code to dismiss the self as modal view. This work fine till here.

But after 30 seconds I redraw my view by calling the server to get latest data and after view is drawn again when I tap on "Cancel" button I get a crash -- Only on IOS 5.0. Any clue for this?

[self dismissModalViewControllerAnimated:YES];

Error:

Single stepping until exit from function -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]

This is the screenshot of error in the thread trace:

enter image description here

Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • same problem I have , as I think: http://stackoverflow.com/questions/11832981/dismissviewcontrolleranimated-crash-at-ios5 –  Aug 07 '12 at 15:59

3 Answers3

1

If the administrator allows me to add a new comment (my last one was removed) I could explain what was happening in my case.

There is something in this link that I recognise I was doing wrong.

The problem comes when presenting the view, however the application crashes when dismissing it. Now, what is the problem? In my code I was presenting the view immediately next to a popToRootViewControllerAnimated: call. As you can see in link I have just pasted, iOS5 seems to have some restriction when presenting modal views. As a summary of the link, you cannot make presentModalViewController:animated: before viewDidLoad and viewWillAppear: are finished:

It turns out that iOS guidelines don't want model view controllers to be presented in viewDidLoad or in viewWillAppear

That was exactly my fault. What can you do if this is happening to you? You can present the modal view after a delay. So, instead of using this:

[[self navigationController] popToRootViewControllerAnimated:NO];
[self presentModalViewController:loginNavController animated:YES];

you should use this:

[[self navigationController] popToRootViewControllerAnimated:NO];
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentModalViewController:loginNavController animated:YES];;
});

(I suppose a performSelector:afterDelay: also works)...

and make sure delayInSeconds is big enough to let viewDidLoad and viewWillAppear finish. Sorry if this not very accurate and elegant, but at least it works.

Regards.

Mr Spiegel
  • 66
  • 5
  • doesn't help me at : http://stackoverflow.com/questions/11832981/dismissviewcontrolleranimated-crash-at-ios5 –  Aug 07 '12 at 15:59
  • @PaulCezanne it seems the blog post has been dismissed. However my answer is an extract of the content. – Mr Spiegel Sep 01 '17 at 07:52
1

try

[[super presentingViewController] dismissModalViewControllerAnimated:YES];

rjm619
  • 81
  • 2
  • If i try this it wont work but if i try like this [[super presentedViewController] presentModalViewController:mailer animated:YES]; it will work but still crashes. – Gaurav Jul 31 '12 at 06:57
  • doesn't help me at: http://stackoverflow.com/questions/11832981/dismissviewcontrolleranimated-crash-at-ios5 –  Aug 07 '12 at 15:58
0

Is there another reference to the controller somewhere? If not, then you are releasing your object on dismissal but you are still inside one of its methods.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • I think he is doing [self dismissModalViewControllerAnimated:YES]; in parent viewController, not inside the modal one. I have the same problem in several apps, that were fine before and now something simillar happens on iOS 5. – Artur Ozierański Oct 25 '11 at 19:22
  • I am calling [self dismissModalViewControllerAnimated:YES] from my modal view. And it works fine until I do not redraw my view. Once view is redrawn it starts crashing here. It works fine on all IOS other than IOS 5.0 all the time. – Abhinav Oct 25 '11 at 19:28
  • @ArturOzierański You are right, my bad. But I still think it could be a zombie problem. Do you have zombie detection enabled? – Sulthan Oct 25 '11 at 20:52
  • How to enable zombie? And how does it help it tracking the issue. – Abhinav Oct 25 '11 at 21:08
  • Product->Edit Scheme -> Run -> Diagnostics -> Enable Zombie Objects. This is detecting if you are not using objects which were already deallocated. A must for every iOS developer. You should also try to profile for Memory leaks. – Sulthan Oct 25 '11 at 21:51