[self dismissModalViewControllerAnimated:YES]; Worked for quite some time. One of the best secrets in iOS development if you ask me.
However, self.parentViewController does not actually work new to iOS 5. It has been "replaced" by self.presentingViewController .
This causes an interesting problem for code that tries to be compatible with pre-iOS 5. Since, as you discovered, self.parentViewController returns nil on iOS 5. And UIViewControllers does not respond to presentingViewController pre-iOS 5.
This leaves us with something like this:
if ([self respondsToSelector:@selector(presentingViewController)]){ [self.presentingViewController dismissModalViewControllerAnimated:YES]; } else { [self.parentViewController dismissModalViewControllerAnimated:YES]; }
source share