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.