codingPanda
codingPanda

Reputation: 255

iPad: Content view is not resized to fit popover

I'm having some trouble with presenting a content view in a popover. I'm using the following code to set up the popover with a view controller which I instantiate from the storyboard. The view controller in which I'm presenting the popover is within a navigation controller :

    MyViewController *viewController =  [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
    viewController.contentSizeForViewInPopover = CGSizeMake(382, 502);
    UIPopoverController *popover =  [[UIPopoverController alloc]initWithContentViewController:viewController];

    self.popoverController = popover; //self.popoverController is a private property of type UIPopoverController
    [self.popoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Here comes the problem: When I tap the left bar button the popover shows in the correct size with the correct content, but the content view is not resized to the size of the popover. Only the snippet of the content view which is "covered by the popover" is visible.

I'm having the same procedure with a table view, which is working perfectly-the table is fitted to the popover. I also tried to set the size of the popover controller itself, like it is suggested here. And I tried out some settings with the springs and struts of the affected view controller. But the outcome is always the same.

Now I really run out of ideas what I could try out, or what I'm possibly doing wrong/missing...HELP :(

Thanks in advance!

Upvotes: 2

Views: 3004

Answers (2)

sketchyTech
sketchyTech

Reputation: 5906

There were some changes between iOS 6 and iOS 7 that mean views don't always resize as expected. A number of different methods and techniques can be used to provide the desired behaviour. These include providing guidance via the autoresizing mask:

// Resizing behaviour
self.view.autoresizingMask=UIViewAutoresizingFlexibleWidth+UIViewAutoresizingFlexibleHeight;

And sometimes the parent view needs to be told to resize subviews as well.

self.view.autoresizesSubviews=YES;

In addition Matt Neuberg (Programming iOS 7) tells us how to prevent content being hidden underneath the navigation bars (and toolbar), using the following:

// Stops the view going underneath the navigation bars 
self.edgesForExtendedLayout=UIRectEdgeNone;

Then there is the:

[self.view setNeedsLayout];

method used for redrawing. The first step is learning that all these weird and wonderful methods exist and the second is to find out the most economical implementation to get them all working for you.

Upvotes: 0

uulhaa
uulhaa

Reputation: 121

A TableView adjusts itself to the size of the container view controller it is put in. That is a feature of a UITableViewController. When you present the TableView by UIPopoverController, the popover determines the size for the table.

This mechanism does not work for all views, so you need to set the size of your view itself as well.

Upvotes: 1

Related Questions