UIPopoverController w / UINavigationController Subview contentSizeForViewInPopover does not work on parent

I have a UIPopoverController with a subclass of UINavigationController. The parent and child view are UITableviews.

When I call the parent view initially with contentSizeForViewInPopover = (320,480), it works fine.

When I click on the child view, I resize the popover to contentSizeForViewInPopover = (320,780)

Returning to the parent view, I cannot force popover to resize to contentSizeForViewInPopover = (320,480). popover remains in the amount of (320,780).

I tried everything, but something was missing. Does anyone know how to resize a view using UIPopoverControllers in the above script?

Thanks at Advance !!

+16
iphone resize uipopovercontroller
May 28 '10 at 2:25
source share
6 answers

I had the same problem, but none of the above solutions worked for me. However, trying to combine my approaches, I was offered a slightly different approach to attack the problem. This works for me:

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size; } 

I have three different popovers, each of which uses navigation view controllers. This solution has a good side effect to work for all of them, as it does not specifically reference any of the popover controllers, but ends up using popoverContentSize from the currently used popover controller.

+13
Aug 18 '11 at 10:22
source share

The contentSizeForViewInPopover property for the view controller sets only the initial size (its initial size) containing the UIPopoverController . To resize the UIPopoverController at any time, you must set the popoverContentSize property. Note that popoverContentSize is a property of UIPopoverController and not a view controller (so you probably need a link to the popover controller).

To reset the size of the popover each time the view controller becomes the top-level controller of the UINavigationController , you can use the UINavigationControllerDelegate protocol methods:

 navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if (viewController == viewControllerToResize) { referenceToUIPopoverController.popoverContentSize = CGSizeMake(320,480); } } 
+24
Aug 02 '10 at 18:37
source share

In my project, I had to dynamically resize the popover.

I made a delegate to the source controller of my popover content controller and implemented its delegation method, which is called every time the size changes:

The code below, hope it helps someone:

 -(void) popover:(UIViewController*)controller didChangeSize:(CGSize)size{ if ([controller class] == [AZViewController class]){ if (!_popoverController){ _popoverController = [[UIPopoverController alloc] initWithContentViewController:controller]; } _popoverController.popoverContentSize = size; } } 
+2
May 24 '11 at
source share

I think I had the same problem, and I solved it by setting the size for the view to popover every time the view appears. Like this:

 - (void) viewWillAppear: (BOOL) animated {
     [super viewWillAppear: animated];

     self.contentSizeForViewInPopover = CGSizeMake (320, 444);  // Set your own size
 }

Hope this helps you.

+1
Jun 01 '10 at 14:19
source share

I think I could understand this because for some time I struggled with this problem. May be a little optimistic, so please feel free to comment if this solution does not work for you.

In each viewController displayed using the navigation hierarchy, set the contentSizeForViewInPopover property in the viewDidAppear method: its corresponding size.

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self setContentSizeForViewInPopover:CGSizeMake(320, 320)]; } 

Another thing that I chose is that when you click on the edit text field, the size remains small, not a larger previous view. Call the resignFirstResponder method on your text box in the controller view of WillDisappear.

I am wondering if this solution works through sdks.

+1
Sep 13 '11 at 8:01
source share

After trying a lot of things, @ chuck-k's answer helped me decisively solve my problems with the UINavigationController in iOS7.

Here is what I did:

  • for each UIViewController in the UINavigationController. I calculate the size of the content I want to display in the method - (CGSize)contentSizeForViewInPopover plus navigationController.navigationBar.frame.size.height (which is always 44, I think). I do not use any other popover functions in these UIViewControllers.

  • I announced that my UIViewController creates a UINavigationController as a UINavigationControllerDelegate

  • Then in the delegate ....

.....

 - (void)navigationController:(UINavigationController *)navigationController willShowViewController: (UIViewController *)viewController animated:(BOOL)animated { BOOL popoverAnimation = NO; if ( self.myPopoverController.popoverContentSize.height < viewController.contentSizeForViewInPopover.height ) popoverAnimation = YES; [self.myPopoverController setPopoverContentSize:viewController.contentSizeForViewInPopover animated:popoverAnimation]; } 

The height check compares the current size of the contents of the content of the view controller with the inbound controller. I use animation = NO when moving from a larger → smaller size popover content, because otherwise I get some sharp repositioned animation in iOS7. But especially if animation = NO when moving from a smaller → larger size of the popover content, the size of the popover will increase to the size that I expected , but did not display the content more than the previously smaller size of the content ... setting animation = YES solved this problem for me. (I only check the height, because in my case the width is fixed.)

Using this technique, almost everything finally works to my satisfaction, and I hope this can help someone else.

0
Oct 31 '13 at 0:45
source share



All Articles