Reputation: 414
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.
Upvotes: 0
Views: 1335
Reputation: 414
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.
Upvotes: 2
Reputation: 8163
Just use
- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated
like this:
[popoverController setPopoverContentSize:size animated:NO];
Upvotes: 1