UIPopoverController w/ UINavigationController Subview contentSizeForViewInPopover doesnt work on Parent

Abbacore picture Abbacore · May 28, 2010 · Viewed 16.3k times · Source

I have a UIPopoverController with a subclass UINavigationController. Both the parent and child views are UITableviews.

When i call parent view originally with contentSizeForViewInPopover = (320,480) it works great.

When i click into the child view i resize the popover to contentSizeForViewInPopover = (320,780)

When return back to the parent view i cannot get the popover to resize back to contentSizeForViewInPopover = (320,480). the popover stays at the (320,780) size.

Been trying everything but just missing something. Anyone know how resize the view with UIPopoverControllers in the above scenario?

Thanks in Advance!!

Answer

cristoper picture cristoper · Aug 2, 2010

The contentSizeForViewInPopover property of the view controller only sets the default (initial) size of its containing UIPopoverController. To resize the UIPopoverController at an arbitrary time, you must set its popoverContentSize property. Note that popoverContentSize is a property of the UIPopoverController and not of the view controller (so you'll probably need a reference to the popover controller around).

To reset the popover's size every time a view controller becomes the top view controller of a UINavigationController, you can use the UINavigationControllerDelegate protocol methods:

navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController == viewControllerToResize) {
        referenceToUIPopoverController.popoverContentSize = CGSizeMake(320,480);
    }
}