开发者

How to change height of the popoverController when one of its viewControllers gets popped?

I have a SplitViewController based app. It uses a rootViewController inside a popoverController. The rootViewController sets the height of th开发者_Go百科e popover by specifying (in viewDidLoad)

self.contentSizeForViewInPopover = CGSizeMake(320.0, 573.0);

When you select a row in the rootViewController, it pushes a secondViewController. The secondViewController makes the popover taller by specifying (in viewDidLoad):

self.contentSizeForViewInPopover = CGSizeMake(320.0, 900.0);

When the user taps on the back button to pop the secondViewController, the height of the popover stays taller. I would like to adjust the height back to the original size. I tried setting contentSizeForViewInPopover in viewWillAppear and also in navigationController's willShowViewController delegate methods. But these did not have any effect.


FWIW, I worked around this problem by manually resizing the popoverController in my view's viewWillAppear method. In other words, I set self.contentSizeForViewInPopover in -[viewDidLoad] and set popoverController.popoverContentSize in -[viewWillAppear:]. Of course, this requires that you save a pointer to the popoverController.


A better way to do this is to change the navigation controller's contentSizeForViewInPopover property. This way you don't need a pointer to the popover controller. Here's how I implemented it in my view controller (in viewDidAppear):

self.contentSizeForViewInPopover = someSize;
if (self.navigationController)
    self.navigationController.contentSizeForViewInPopover = someSize;

This implementation also takes care of the case where the view controller doesn't have a navigation controller. If you change the navigation controller's property without also changing the view controller's (self), it won't work. Also, it didn't work for me in the viewWillAppear method.


We've found that the selected solution is best, except that it's probably a bad design idea to have a reference to the popover in the view. Instead, set the UINavigationController's delegate and handle it in navigationController:didShowViewController:animated:. In our case, this is best handled in the place that the popover is displayed, thus already having access to the popoverController.

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [popoverController setPopoverContentSize:viewController.contentSizeForViewInPopover];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜