I have a popover containing a UINavigationController. I can display the popover fine, and it contains the navController just fine. The navController contains a tableView a
This fixed it for me after I had the same issue (coincidently also today):
EDIT : As contentSizeForViewInPopover
is deprecated in iOS7.0
so use preferredContentSize
.
Original answer below:
In your detailViewController
add this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
self.contentSizeForViewInPopover = size;
[super viewWillAppear:animated];
}
You also want to add something similar to your original DeviceDetailViewController to prevent resizing when tapping the back NavbarItem.
For IOS5
I recommend you do it in:
- (void)viewDidLoad {
[super viewDidLoad];
CGSize size = CGSizeMake(320, 480); // size of view in popover
self.contentSizeForViewInPopover = size;
}
For iOS 7 use the following:
- (void)viewDidLoad
{
[super viewDidLoad];
CGSize size = CGSizeMake(320, 768); // size of view in popover
self.preferredContentSize = size;
}
UIViewController.contentSizeForViewInPopover
has been deprecated first in iOS 7.
Slight varient on borked's advice (which pointed me in the right direction, thanks for that!), here's what I do when pushing a new controller to maintain the size before pushing it:
productViewController.contentSizeForViewInPopover = self.view.bounds.size;
self.contentSizeForViewInPopover = self.view.bounds.size;
[self.navigationController pushViewController:productViewController animated:YES];
I like this because I don't have to hardcode the popover values in every view controller (good since I use them at various heights).
The self.contentSizeForViewInPopover
line is to preserve the size when the user hits back. I guess you could put this line somewhere else, like viewWillAppear
or wherever you like.
Seems to work...
In the -(void)viewDidLoad of all the view controllers you are using in navigation write the code:
self setContentSizeForViewInPopover:CGSizeMake(320, 500)];
There are two ways to set the contentSizeForViewInPopover in the storyboard. You can set your view controllers that are with your navigation controller, to FreeForm and set the root views to the desired size. Or, you can keep the simulated metric as inferred and check "Use Explicit Size" and set the size you want there.
Then, in each view controller that is within your navigation controller, add the following...
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
["yourpopoverController" setPopoverContentSize:CGSizeMake(self.
contentSizeForViewInPopover.width, seld.contentSizeForViewInPopover.height + self.
navigationController.navigationBar.frame.size.height) animated:YES];
}
In the transition animation, the new view will come in aligned with the top, and then the height will be adjusted accordingly.
This way, you don't have to override contentSizeForViewInPopover, or specify some other size specifically in your view controllers. It's all in the storyboard.
If one of your view controllers has a variable height, then you do need to override contentSizeForViewInPopover in that view like so...
- (CGSize)contentSizeForViewInPopover {
return CGSizeMake(450, "calculate your height here");
}