Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverController w/ UINavigationController Subview contentSizeForViewInPopover doesnt work on Parent

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!!

like image 730
Abbacore Avatar asked May 28 '10 02:05

Abbacore


3 Answers

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);
    }
}
like image 143
cristoper Avatar answered Nov 12 '22 11:11

cristoper


I had the same problem, but none of the above solutions worked for me. However, in trying to combine their approaches, I was inspired to try a slightly different way to attack the problem. This works for me:

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size;
}

I have three different popovers that each use navigation view controllers. This solution has the nice side effect of working for all of them because it doesn't make a specific reference to any of the popover controllers, but ends up using the popoverContentSize from the popover controller currently being used.

like image 25
Chuck H Avatar answered Nov 12 '22 11:11

Chuck H


In my project I had to dynamically change the size of the popover.

I made the original controller delegate of my popover content controller, and implemented it's delegate method that is called each time the size is changed:

The code is bellow, hope it helps somebody:

-(void) popover:(UIViewController*)controller didChangeSize:(CGSize)size{

    if ([controller class] == [AZViewController class]){
        if (!_popoverController){
            _popoverController = [[UIPopoverController alloc] initWithContentViewController:controller]; 
        }

        _popoverController.popoverContentSize = size;
    }
}
like image 2
Vadim Fainshtein Avatar answered Nov 12 '22 09:11

Vadim Fainshtein