title: Animate popoverContentsize when pushing navigation view controller in popover on iPad
body: <h3>How do I get my UIPopoverController to animate its size when its contained UINavigationController pushes a new controller?</h3>
  <p>I have a <code>UIPopover</code> being displayed from a <code>UIBarButtonItem</code> in my iPad app.  It contains a <code>UINavigationViewController</code>, which has a sort of settings window as its root view controller.  The settings window is a subclass of <code>UITableViewController</code> (style set to grouped), and tapping any of its cells pushes different &quot;chooser&quot; view controllers on the nav controller that are also subclasses of <code>UITableViewController</code>.</p>
  <p>For each of the chooser views, in <code>viewDidAppear</code>, I'm setting <code>contentSizeForViewInPopover</code> appropriately:</p>
  <pre><code>self.contentSizeForViewInPopover = CGSizeMake(320, self.items.count * 44);
  </code></pre>
  <p>But it doesn't animate the change; when the navigation animation finishes, the popover snaps to the new height (width never changes from 320).  Navigating backward animates the size change (accomplished with the technique from <a href="https://stackoverflow.com/a/5032887/412107">this answer</a>), but forward never does.</p>
  <p>I've tried obtaining a reference to the popover it's in and using <code>setPopoverContentSize:animated:</code> but it doesn't work.  I've looked at <a href="https://stackoverflow.com/questions/7105548/setpopovercontentsize-not-working">other</a> <a href="https://stackoverflow.com/questions/5527408/problem-in-setting-popovercontentsize">questions</a> to no avail.</p>
  <p>How do I get it to always animate the size change properly?</p>
  <p><b>Update:</b> I've set up a simple test project to try this out.  It's a tab bar application for iPad set up in Xcode.  I added a tab bar item to the navigation bar in one of the view controllers.  When that button is pressed, the controller presents a popover that contains a navigation controller that has a very simple <code>UITableViewController</code> subclass, called <code>TestContentViewController</code>, as its root view controller.</p>
  <p>In <code>viewDidLoad</code> of that subclass, I randomly generate a number of items:</p>
  <pre><code>self.numItems = arc4random() % 10 + 3;
  </code></pre>
  <p>This is my number of rows; number of sections is 1.  In <code>cellForRowAtIndexPath</code> I just set the cell's label text and return it.  When a row is selected, I generate another instance of the same class and push it on the stack.</p>
  <p>Without doing anything at all with the <code>contentSizeForViewInPopover</code> property on any VC, the popover just goes to its maximum height and stays there no matter how many rows are in my table view.</p>
  <p>If I set the size in viewDidAppear, like this:</p>
  <pre><code>-(void)viewDidAppear:(BOOL)animated
  {
    self.contentSizeForViewInPopover = CGSizeMake(320, self.numItems * 44);
    [super viewDidAppear:animated];
  {
  </code></pre>
  <ul>
  <li>When the popover first appears, it flashes very quickly to full height and then snaps to the height I set.</li>
  <li>When a new controller is pushed on the navigation controller, it snaps to its height with no animation.</li>
  <li>When I navigate back, if the VC that I'm popping to is taller than the one I'm popping from, it animates to the correct size.  If what I'm popping to is smaller, it does nothing.</li>
  </ul>
  <p>If I do the same thing but in <code>viewWillAppear</code>:</p>
  <ul>
  <li>When the popover first appears, it's full-height</li>
  <li>When I first tap a row and get a new controller on the stack, it animates to a minimum of about 400px tall.  When a new controller is pushed on the stack, if it needs more height it gets it.  If not it stays at what it was before.</li>
  </ul>
  <p>If I do the same thing in <code>viewDidLoad</code>, it's basically the same as <code>viewWillAppear</code> except it appears at the right size at first.</p>
  <p>I've tried setting the nav controller's delegate to be the VC that presents the popover, and then set the popover's height (<code>setPopoverContentSize:animated:</code>) in <code>navigationController:didShowViewController:animated:</code>, but the resultant height is off by a little bit.  I think the size I set there needs to take into account the extra height of the navigation bar built into the top of the popover.  And the animation when pushing a new controller on the stack is weird.</p>
  <p><b>Update again:</b> See <a href="https://stackoverflow.com/questions/32719625/how-can-i-make-uipopoverpresentationcontroller-resize-on-navigation-pop">here</a> for the same problem solved with the newer <code>UIPopoverPresentationController</code>.</p>