contentSizeForViewInPopover different height in IOS4 and IOS5
-
03-06-2021 - |
Question
Hello, I have UITableView with static content embedded in UIScrollView so I have just set size in popover:
- (CGSize)contentSizeForViewInPopover
{
return CGSizeMake(600, 670);
}
but, I got different popover heights (see attachments). In IOS4.3 height is bigger than in IOS5. I don't want to check IOS version and increase/decrease height.
Please advice.
Thanks
Solution
As far as I know, when using the navigation controller as popover contents, you have to
set the
contentSizeForViewInPopover
on the root controller (or anyone that is being shown as the first). (Don't try to set size on the navigation controller).whenever you push/pop controllers and you want the popover size changed for the new controller on the stack, call
setPopoverContentSize:animated:
explicitly. AUINavigationControllerDelegate
is good for this.
OTHER TIPS
You can dynamically calculate the height of your popover based on the height of your tableview and overriding contentSizeForViewInPopoverView
like this:
- (CGSize)contentSizeForViewInPopoverView {
CGFloat width = 200.0; // Currently no way to obtain the width dynamically, only height.
CGRect rect = [self.tableView rectForSection:[self.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
return (CGSize){width, height};
}
This assumes you have 1 section. If you have more, you just need to use rectForSection
to determine the height of each section and add them up.