Search code examples
ioscocoa-touchuipopovercontroller

Change UIPopoverController on the fly


one UIPopoverviewController is currently visible....
its ViewController contains a button and clicking on the button changes the PopoverviewController's viewController to some other viewController.

Works great, viewController changed Successfully......
but PopoverViewController's contentsize is still same

lets change the contentSize manually
Step1 : View Controller changed
Step2 : popoverviewController.popovercontentSize = CGSizeMake(500,500);

:( Still No change in Size

NOTE: Both the View Controller loading successfully and if contentsize of popover is big enough to hold both then both viewController is Visible....


Solution

  • [UIViewController contentSizeForViewInPopover] is read only once - when the popover is shown. You can look at it as the initial value for the popover controller's size.

    However, once the popover is shown, it won't ever be read again, even if you change the contentViewController.
    You have to use [UIPopoverController setPopoverContentSize:animated:] instead.

    UIPopoverController* popover = [... already existing and visible popover ...];
    UIViewController* newPopoverContents = [... new content for the popover ...];
    
    [popover setPopoverContentSize:newPopoverContents.contentSizeForViewInPopover
                          animated:YES];
    [popover setContentViewController:newPopoverContents 
                             animated:YES];