问题
My app which use to work perfectly being compiled in xCode 4.0.2 no longer works correcly compiled in xCode 4.2 with the new SDK.
My modal views are working very different, some states not being detected, or other dismissals not working. For example this use to work to dismiss 2 stacked modal views:
if(self.parentViewController.parentViewController)
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
Now this just dismisses the first view...
I've been looking for documentation on these changes but have found none. Primary app delegate seems to be working differently too.
Help greatly appreciated.
回答1:
There is a new property in iOS 5 named presentingViewController
. The meaning of parentViewController
got changed a bit with the new container view controller API, so it may not always be set when you think it is. That's what presentingViewController
is now for.
回答2:
if ([self respondsToSelector:@selector(presentingViewController)])
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}
来源:https://stackoverflow.com/questions/7779195/ios-5-sdk-treating-uiviews-differently