Reply to comment
Behavior changed for parentViewController in iOS 5
Previously, if we present a modal view controller using:
[self presentModalViewController:modalViewController animated: YES]
We should able to get back the parent of the modal view controller using:
[modelViewController parentViewController]
and normally we will dismiss the view controller using:
[[modelViewController parentViewController] dismissModalViewControllerAnimated:YES];
However, after iOS 5, the behavior of parentViewController is changed, that it will return nil for the modal view controller. Instead, it's parent view controller can be given by the new accessor presentingViewController. i.e. the old parentViewController spited to parentViewController and presentingViewController
To fix the problem, I create the following defines:
#ifndef __presentingViewController
#define __presentingViewController(obj) (([obj respondsToSelector:@selector(presentingViewController)]) ? [obj presentingViewController] : [obj parentViewController] )
#endif //__presentingViewController//
Then we can use:
__presentingViewController(modelViewController)
instead of:
[modelViewController parentViewController]
Actually the dismiss a modal dialog, instead of:
[[modelViewController parentViewController] dismissModalViewControllerAnimated:YES];
we can simply called:
[modelViewController dismissModalViewControllerAnimated:YES];
so that we can avoid calling parentViewController in many cases.

Recent comments
32 weeks 4 days ago
37 weeks 6 days ago
41 weeks 1 day ago
42 weeks 1 day ago
51 weeks 3 hours ago
51 weeks 3 hours ago
51 weeks 1 day ago
51 weeks 2 days ago
1 year 6 days ago
1 year 1 week ago