Padin215
Padin215

Reputation: 7484

Resizing UIPopoverController

I have a UIPopoverController. I put a UINavigationController with two UITableViewcontrollers in it.

I create a subclassed UITableView, I'm able to set the size of the popover with tableView.contentSizeForViewInPopover:

if (self.myPopoverController.isPopoverVisible)
{
    [self.myPopoverController dismissPopoverAnimated:YES];
}
else
{
    MyRootTableView *rootTableView = [[MyRootTableView alloc]initWithStyle:UITableViewStyleGrouped];
    MyRootTableView.contentSizeForViewInPopover = CGSizeMake(POPOVER_SIZE.width, [self createContentHeighForTableViewController:tableView]);
    MyRootTableView.boundaryDelegate = self;

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navController.navigationBar.barStyle = UIBarStyleBlack;

    self.myPopoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
    self.myPopoverController.delegate = self;

    [self.myPopoverController presentPopoverFromRect:frame inView:view permittedArrowDirections:arrowDirection animated:YES];
}

In the rootTableViewController's didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailedTableViewController *tableViewController = [[DetailedTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    tableViewController.contentSizeForViewInPopover = CGSizeMake(POPOVER_SIZE.width, [self createContentHeighForTableViewController:tableViewController]);
    tableViewController.delegate = self.boundaryDelegate;

    [self.navigationController pushViewController:tableViewController animated:TRUE];
}

createContentHeightForTableViewController: calculates the height needed to show all the cells in the table view

So for the root tableViewController, I set the content size. When I create the detailed view controller, I set the contentSizeForViewInPopover to a different size. This works great. The issue I'm having is when I navigate back to the root table view, the contentSizeForViewInPopover is still set for the detail table view.

How can I resize the pop over when the table view is displayed or appears?

Upvotes: 0

Views: 4538

Answers (2)

Alberto Malagoli
Alberto Malagoli

Reputation: 1195

Try to use preferredContentSize instead of contentSizeForViewInPopover on your tableViewController (contentSizeForViewInPopover is deprecated on iOS7)

Upvotes: 3

Aaron Golden
Aaron Golden

Reputation: 7102

You should set popoverContentSize on the UIPopoverController directly in the viewWillAppear method of your parent view controller (or some other appropriate place). Wherever you want to force the popover's content size to update.

Upvotes: 0

Related Questions