Search code examples
iosobjective-cuitableviewuipopovercontroller

Change the width of a popover which has table view in it


I'm trying to achieve two things:

To change the height of the popover to the number of cells in my static table view (which works).

But for the popovers width to be configurable using the storyboard builder.

- (void)viewDidLoad
{
    CGRect popoverBounds = self.view.frame;

    [self.tableView sizeToFit];

    CGRect newBounds = self.tableView.bounds;
    newBounds.size.width = popoverBounds.size.width;
    self.tableView.bounds = newBounds;

    self.preferredContentSize = self.tableView.contentSize;
}

currently this sets the popover to the width of the table view.

enter image description here


Solution

  • Problem is inside this line:

    self.tableView.bounds = newBounds;
    

    You change internal bounds, instead of frame, you need to use:

    self.tableView.frame = newBounds;