How to change the height of a popoverController when one of its viewControllers appears?

I have a SplitViewController based application. It uses rootViewController inside popoverController. RootViewController sets popover height by specifying (in viewDidLoad)

self.contentSizeForViewInPopover = CGSizeMake(320.0, 573.0); 

When you select a row in the root controller, it pushes the secondViewController. SecondViewController makes a popover above by specifying (in viewDidLoad):

 self.contentSizeForViewInPopover = CGSizeMake(320.0, 900.0); 

When the user clicks on the "Back" button to pop up the second control controller, the height of the pop-up window remains higher. I would like to adjust the height back to the original size. I tried setting the contentSizeForViewInPopover in viewWillAppear, as well as in the delegation methods of navigationController willShowViewController. But it had no effect.

+4
source share
3 answers

FWIW, I worked on this issue by manually resizing the popoverController in my viewWillAppear view. In other words, I set self.contentSizeForViewInPopover to - [viewDidLoad] and set popoverController.popoverContentSize to - [viewWillAppear:]. Of course, this requires you to keep a pointer to the popoverController.

+4
source

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

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

This implementation also relates to the case where the view controller does not have a navigation controller. If you change the property of the navigation controller without changing the controller (self) as well, it will not work. Also, this did not work for me in the viewWillAppear method.

+4
source

We found that the chosen solution is the best, except that probably a bad design idea has a link to the popover in the view. Instead, set the delegate to UINavigationController and process it in navigationController:didShowViewController:animated: In our case, this is best handled in the place where the popover is displayed, thereby already having access to the popoverController.

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

Source: https://habr.com/ru/post/1308378/


All Articles