Reputation: 1055
my UIPopOverController loses its content sometimes, when being rotated (not reproducable) or if for example I open some content from a tableview in landscape, rotate the device to portrait and then open the same content in portrait.
The Popovercontroller is displayed but no content is visible i.e. it is black.... has anyone stumbled upon this or anything similar?
Upvotes: 1
Views: 1854
Reputation: 196
I encountered similar problems when using UIPopoverController after rotation occurred (UIPopoverController's size changed strangely, it repositioned itself to strange places in screen etc).
The trick that worked for me was to overload the UIViewController's didRotateFromOrientation:(UIInterfaceOrientation) method in the app. So overload the method from your app's UIViewController class that is being displayed when UIPopoverController is displayed and call UIPopoverController's presentPopoverFromRect: method again from there:
-(void) didRotateFromOrientation:(UIInterfaceOrientation)uiOrientation {
if (popoverController.popoverVisible) {
// Define rect to be the UI component's rect where you want to tie the popoverController
CGRect rect = CGRectMake(...);
// This method will reposition the popover correctly
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
}
}
Note that if you are tying UIPopoverController to UIBarButtonItem using UIPopoverController's presentPopoverFromBarButtonItem: method, the system should then automatically take care of positioning the popover correctly after the rotation.
Upvotes: 4