2

I found this thread, but it still doesn't fix my problem. UIPopoverController automatically resizing to max height on pushViewController

I have a UIPopoverController that pushes a navigationcontroller. When I present this popover, I set the contentSizeForPopover to 340,340. That works fine. In the popover, I have a button, that pushes a new UITableViewController into the already existing UIPopoverController (code below for the tableViewController).

UITableViewController *contentView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
contentView.tableView.delegate = self;
contentView.tableView.dataSource = self;
[self.navigationController pushViewController:contentView animated:YES];
[contentView release];

When the tableView gets pushed, the height grows to the max height of the iPad. When I press the back button, the height still is at the max height and does not go back to the 340,340 height that was defined when the UIPopoverController was originally created. Is there a way to set this value again for the new tableView I created? Thanks.

Community
  • 1
  • 1
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • If you hold a reference to the popover, you should just be able to say something like `[popover setPopoverContentSize:CGSizeMake:(340, 340)];` when you hit the back button. – justin Oct 31 '11 at 19:55

2 Answers2

3

In my experience with UIPopoverController objects, the popover seems to use the maximum height whenever new content is added to the popover. I send the popover controller a setPopoverContentSize:animated: message every time I change the content, which of course requires me to keep a reference to that popover controller in every object that may cause the popover to resize. You could add that message send right after your sample code in your question to keep the popover from resizing, but it may still resize when you pop off this view from the UINavigationController stack, so another message send may be needed. Maybe each view controller that may appear in the popup will send the setPopoverContentSize:animated: message in its viewWillAppear: method. Each will also have a reference to the popover controller.

Mr. Berna
  • 10,525
  • 1
  • 39
  • 42
  • So it half works. I now created a method to set the popoverContentSize to the size I want. I call that method using the observer pattern (using NSNotification). So I see that the UITableView resizes, then it gets big again. I put the notification right after the block I had in my original post. If I move the notification to some time later like after something in the table is selected, then it stays at the smaller size. This seems clunky though since the table goes big, you click, then it goes small. Any thoughts on where else I could put the notification? Thanks. – Crystal Oct 31 '11 at 21:42
  • Did you try setting the size in the viewWillAppear: method of the view controllers? I would set the size of the pop over (setPopoverContentSize:animated:) and the controller's view (self.contentSizeForViewInPopover = CGSizeMake(340.0, 340.0);). – Mr. Berna Nov 01 '11 at 14:14
1

All that you have to do is:

-In the viewWillAppear method of the popOvers contentView, add the snippet given below. You will have to specify the popOver's size first time when it is loaded.

-(void)viewWillAppear{
CGSize size = CGSizeMake(width,height);
self.contentSizeForViewInPopover = size;
}
Deepukjayan
  • 3,525
  • 1
  • 20
  • 31