views:

606

answers:

2

I have a popover containing a UINavigationController. I can display the popover fine, and it contains the navController just fine. The navController contains a tableView and when I select an item it creates a new detail view:

     DeviceDetailViewController *detailViewController = 
[[[DeviceDetailViewController alloc] initWithNibName:@"DeviceDetailViewController" bundle:nil] autorelease];

I then push it the new view controller:

    [self.navigationController pushViewController:detailViewController animated:YES];

This is when the problem occurs: after pushing the new view the popover resizes to the maximum height available on the iPad.

I have tried setting the height of all the views in the xib to fixed height rather than flexible. I have tried explicitly setting the height of the popover. I have also tried using different view controllers as the child view. The problem remains: the popover wants to resize itself to max height automatically whenever a new view is pushed to the navigation controller.

Here's a question which discusses trying to deliberately control the size of the popover when pushing new views: http://stackoverflow.com/questions/2926308/uipopovercontroller-w-uinavigationcontroller-subview-contentsizeforviewinpopover

I thought this might be a brute force method to control the size. Strangely enough, though, it actually causes some quick graphics quirks (as if the view were being freshly animated in) followed by continuing to resize as described above.

In other words, something is literally forcing the popover to its maximum height, and it seems to occur after all delegate methods have been called.

Is it the navigation controller? Has anyone seen this kind of thing?

+3  A: 

This fixed it for me after I had the same issue (coincidently also today):

In your detailViewController add this:

- (void)viewWillAppear:(BOOL)animated {

    CGSize size = {320, 480}; // size of view in popover
    self.contentSizeForViewInPopover = size;

    [super viewWillAppear:animated];

}

You also want to add something similar to your original DeviceDetailViewController to prevent resizing when tapping the back NavbarItem.

borked
Thanks! I had the same problem and UIViewController's contentSizeForViewInPopover attribute fixed it.
titaniumdecoy
A: 

In response to graphical glitches with animations:

The UIPopoverController animations conflict with the UINavigation controllers animations, if you create the popover with a UINavigationController inside it. It results in graphical glitches when animating. To fix the issue, set animated parameter to false when pushing other controllers, or when displaying the toolbar.

Pushing View Controllers:

[self.navigationController pushViewController:detailViewController animated:NO];

Making the Toolbar visible:

[[self navigationController] setToolbarHidden:NO animated:NO]; 

Setting the animated:NO will make the animations look correct in a UIPopoverController.

Paul Solt

related questions