Q:

ABPersonViewController causes UIViewControllerHierarchyInconsistency on iPad when choosing a photo

I am using an ABPersonViewController in a UINavigationController to display and edit contact information. This has worked up until now using the latest xcode version (4.5.2 currently) and iOS6. If the user selects the Edit button on the ABPersonViewController the view goes into edit mode (as expected) but now if they choose Photo (to add or change an existing photo) then "Choose Photo" the application crashes with the following exception?...
** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View ; }; layer = > is associated with <_UIActionSheetHostingController: 0x4da1190>. Clear this association before associating this view with <_UIActionSheetHostingController: 0x5f38830>.'*
It seems to be specific for iPad - I imagine it has something to do with how the iPad treats action sheets as popovers unless displayed within a popover. Any help would be greatly appreciated.

A:

This seems to be an issue with the new orientation methods of UIViewController:
- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

It seems the choose-photo VC does not implement them, so make sure that your root VC does implement them even when its top VC doesn't.
In code:
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate {
    return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations {
    UIInterfaceOrientationMask topControllerOrientationMask = [self.topViewController supportedInterfaceOrientations];
    return topControllerOrientationMask ? topControllerOrientationMask : UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    UIInterfaceOrientation topControllerOrientation = [self.topViewController preferredInterfaceOrientationForPresentation];
    return topControllerOrientation ? topControllerOrientation : UIInterfaceOrientationPortrait;
}
@end

