Arun Stephens

Modal view controllers and recursion causing stack overflow

Ironically, it was this post at Stack Overflow that helped me solve this problem!

There appears to be a bug (either in the iPhone SDK or my understanding of it) that if you dismiss a modal view controller with animation using UINavigationController’s dismissModalViewControllerAnimated, it will cause some sort of weird recursion that causes a stack overflow (over 4000 frames were in the stack when it crashed, and it took a split second for it to fill up in the Simulator) if you then want to display the modal view controller again using presentModalViewController.

It turns out it’s the animation on dismissal that’s causing the problem. If I have dismissModalViewControllerAnimated:NO instead of YES, the subsequent redisplay of the view works fine.