views:

1674

answers:

3

I have a UIPopoverController hosting a UINavigationController, which contains a small hierarchy of view controllers.

I followed the docs and for each view controller, I set the view's popover-context size like so:

[self setContentSizeForViewInPopover:CGSizeMake(320, 500)];

(size different for each controller)

This works as expected as I navigate forward in the hierarchy-- the popover automatically animates size changes to correspond to the pushed controller.

However, when I navigate "Back" through the view stack via the navigation bar's Back button, the popover doesn't change size-- it remains as large as the deepest view reached. This seems broken to me; I'd expect the popover to respect the sizes that are set up as it pops through the view stack.

Am I missing something?

Thanks.

+4  A: 

You need to set the content size again in viewWillAppear. By calling the delagate method in which you set the size of popovercontroller. I had also the same issue. But when I added this the problem solved.

One thing more,,,,, if you are using beta versions lesser than 5. Then the popovers are more difficult to manage. They seem to be more friendly from beta version 5. its good that final version is out. ;)

Hope this helps.

Thanks,

Madhup

Madhup
I hate this too. It caught me as well. Apple: why can't we lock a popover with navcontroller to a specified size?!
Jann
Setting the content size in `viewWillAppear` didn't work for me. Setting the popover's size explicitly did work, but that's ghetto.
quixoto
+1  A: 
I reset the size in the viewWillDisappear:(BOOL)animated method of the view controller that is being navigated back from:

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    CGSize contentSize = [self contentSizeForViewInPopover];
    contentSize.height = 0.0;
    self.contentSizeForViewInPopover = contentSize;
}

Then when the view being navigated back to appears, I reset the size appropriately:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    CGSize contentSize;
    contentSize.width = self.contentSizeForViewInPopover.width;
    contentSize.height = [[self.fetchedResultsController fetchedObjects] count] *  self.tableView.rowHeight;
    self.contentSizeForViewInPopover = contentSize;
}
Greg C
A: 

For me this solutions works. This is a method from my view controller which extends UITableViewController and is the root controller for UINavigationController.

-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.contentSizeForViewInPopover = self.tableView.bounds.size;

}

And don't forget to set content size for view controller you gonna push into navigation stack

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
dc = [[DetailsController alloc] initWithBookmark:[[bookmarksArray objectAtIndex:indexPath.row] retain] bookmarkIsNew:NO];
dc.detailsDelegate = self;
dc.contentSizeForViewInPopover = self.contentSizeForViewInPopover;
[self.navigationController pushViewController:dc animated:YES]; 

}

Koteg