Dynamically change the contentSize of Popover in UIPopoverViewController

I added a reference in my contentViewController to the popoverController:

(more detail from http://stackoverflow.com/a/12569458)

@property (nonatomic , assign) UIPopoverController *popoverControllerContainer;

Then, I added the resizing code to viewWillAppear and viewDidAppear:

- (void)viewDidLoad
    [super viewDidLoad];
    [self.tableView reloadData];

-(void) viewWillAppear:(BOOL)animated
    [super viewWillAppear:animated];
    self.contentSizeForViewInPopover = self.tableView.contentSize;

-(void) viewDidAppear:(BOOL)animated
    [super viewDidAppear:animated];
    [self.popoverControllerContainer setPopoverContentSize:self.contentSizeForViewInPopover animated:YES];

in PopoverViewController 
add [self reloadViewHeight]; in viewDidLoad method;

I added [self reloadViewHeight]; to viewDidLoad method in the popoverController:

-(void) reloadViewHeight
    float currentTotal = 0;
    //Need to total each section
    for (int i=0;i<[_treeTableView numberOfSections;i++]){
        CGRect sectionRect = [_treeTableView rectForSection:i];
        currentTotal += sectionRect.size.height;
    //Set the contentSizeForViewInPopover
    self.contentSizeForViewInPopover = CGSizeMake(200, currentTotal+20);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s