UIPopoverController automatically resizing to max height on pushViewController

Viewed 49824

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:

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?

13 Answers

I had a similar issue.

I had a popover present from a button in a toolbar. The popover was set to a specific size. It was a table view. When the table row was selected, a new view controller with a navigation controller was called.

When the back button was selected, the popover became the default size (320x1100 I believe), instead of the specific size that I desired.

The original code was:

  MyTableViewController *myVC = [[MyTableViewController alloc] init];
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVC];

  UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
  popover.delegate = self;

  popover.popoverContentSize = CGSizeMake(400.0, 500.0);

  [myVC release];
  [navController release];
  [popover release];

I added one line to solve the problem. Granted it is kind of a work around because I had to subtract the height of the header. Maybe one of you could enlighten me with a better method. Anyway, it works.

  MyTableViewController *myVC = [[MyTableViewController alloc] init];

  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVC];

  UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
  popover.delegate = self;

  popover.popoverContentSize = CGSizeMake(400.0, 500.0);

  //Subtract the height of the header to match the total popover size (not just the view).
  myVC.contentSizeForViewInPopover = CGSizeMake(400.0, 500-44);

  [myVC release];
  [navController release];
  [popover release];

I believe that when a nav controller is involved, and the back button is pressed, it causes the popover to default to its default size. By adding the contentSizeForViewInPopover property for the view controller myVC, it forces the specific size.

Hope this is helpful.

Kurt

Related