Anyway, if you are here because your calls to parentViewController have stopped working, here is the code we are now using. It appears that we need to use "presentingViewController" as well as a new call to dismissViewcontrollerAnimated. This all seems to be related to storyboards in iOS 5. Here is a link to the updated UIViewController documentation that talks about parentViewController and presentingViewController and the new dismissViewControllerAnimated. Right here below, is how we have set up our button to respond to being clicked. In the old days (last month) the method just had the [[self parentViewController] dismissModalViewControllerAnimated:YES] line but we have to add a little more now.
if ([[self parentViewController] respondsToSelector:@selector(dismissModalViewControllerAnimated:)]){
[[self parentViewController] dismissModalViewControllerAnimated:YES];
} else {
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
We have wrapped the whole call into an if statement so that we can still use the old way when on an older phone. The respondsToSelector: test is a good way to deal with using old and new code together. Trying to test for a specific version of iOS by name is pretty brittle; always use the respondsTo method instead.
1 comments:
Thanks a bunch for this! I was struggling with the same issue and your fix worked perfectly.
Post a Comment