Reputation: 38162
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:
Upvotes: 2
Views: 1730
Reputation: 66
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.
Upvotes: 1
Reputation: 130172
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.
Upvotes: 0
Reputation: 81
try
[[super presentingViewController] dismissModalViewControllerAnimated:YES];
Upvotes: 1