Prevent contentSizeForViewInPopover from animating


I have a popover which contains a UITableView. In the storyboard I've set the popover height to fit the entire table, and it displays nicely. However, in some situations I need to display less cells, and in these cases I'd like to change the height of the popover. I do it thus:

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (trimFourCells) { // reduce the popover's height by that of four cells CGSize size = self.contentSizeForViewInPopover; size.height -= 4*60; self.contentSizeForViewInPopover = size; } }

It works well, except that the change is animated: first the full size is shown, then it shrink in about one second.

My question is whether this animation can be disabled.

I have tried to pass NO in [super viewDidAppear:animated], and even tried to move that line after the size change. It did not prevent the animation. Then I tried to move the code to viewWillAppear, and that did not even change the height.


Thanks to @frowing, here is the solution. Instead of changing the size in the popover's code, it has to be done in the caller. I have added code like the following to prepareForSegue:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { UIPopoverController *pc = ((UIStoryboardPopoverSegue*)segue).popoverController; if (trim_nCells > 0) { // trim that many cells from the table CGSize size = pc.contentViewController.contentSizeForViewInPopover; size.height -= trim_nCells * cellHeight; [pc setPopoverContentSize:size animated:NO]; } (... rest of the prep code ...) }

Note that since it's done before the display, there is no animation involved, so the value of the animated: param has no effect.


Just use

- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated

like this:

[popoverController setPopoverContentSize:size animated:NO];


  • Change height constraint of table view outside of viewDidAppear in iOS 7
  • alert with UIAlertController can't dissmiss it
  • MonoTouch SIGABRT “Ran out of trampolines of type 2” error
  • SKPhysicsJointFixed doesn't keep nodes together while moving one
  • Take snapshot / screenshot of whole UIView - iPhone
  • Swift: Make an image in background of label
  • dismissModalViewControllerAnimated nonatomic?
  • How to insert an Image in WORD after a bookmark using OpenXML
  • Hadoop shuffle uses which protocol?
  • UILabel extra spaces before and after text ios
  • finding greatest prime factor using recursion in c
  • “[CALayer release]: message sent to deallocated instance” when dismissing modal view controller
  • Imageloader not loading image on real device
  • “A GKScore must specify a leaderboard.”
  • Deleting a widget from QTableView
  • Jquery UI Sortable, move item automatically
  • multidatatrigger with multibinding in ControlTemplate.Triggers
  • Is there a parser equivalent of 'fragment' marking in ANTLR4?
  • Build Successful but not running on simulator
  • Selenium to click on a javascript button corresponding to a text
  • calculate gradient output for Theta update rule
  • Authentication in Play! and RestEasy
  • How do I configure context broker accept post requests from my remote sensor?
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • What's the purpose of QString?
  • how to avoid repetitive constructor in children
  • Assign variable to the value in HTML
  • custom UITableViewCell with image for highlighting
  • Blackberry - Custom EditField Cursor
  • Content-Length header not returned from Pylons response
  • Change multiple background-images with jQuery
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Android screen density dpi vs ppi
  • Deleting and Updating values from a cusrsor adapter
  • Possible to stop flickering java tooltip in heavyweight mode?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Change an a tag attribute in JavaScript based on screen width
  • Arrays break string types in Julia