Crystal
Crystal

Reputation: 29448

UIPopoverController's content view size

I have a UIPopoverController that I present from a CGRect on iPad like so:

MarkersPopViewController *markersPop = [[MarkersPopViewController alloc] initWithNibName:@"MarkersPopView" bundle:nil];
self.TestPopoverController = [[[UIPopoverController alloc] initWithContentViewController:markersPop] autorelease];
[TestPopoverController presentPopoverFromRect:CGRectMake(20, 20, 700, 500) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

My MarkersPopView is the container view that has a UITableView that takes up the bulk of the .xib, and a UISegmentedControl just above the top of the UITableView. The UITableView uses a custom subclass of UITableViewCell where each row is (700, 100).

When I run my app, the PopoverController is probably only 50 points wide and hugs the left side of the screen. I'd like to make the view the right width for starters, and then center it. Is there a reason why the UIPopoverController is so small? I thought the UIPopoverController uses the default size of the content view if setPopoverContentSize: was not used. Thanks.

Upvotes: 2

Views: 1636

Answers (1)

user467105
user467105

Reputation:

The CGRect passed to presentPopoverFromRect is the rectangle the popover will be displayed on some side of. It's not the frame the popover will appear in.

Since you are requesting the arrow be on the right of the popover, it tries to display the popover to the left of 20,20,700,500.

To display the popover at 20,20 (actually where the arrow tip will be), pass a CGRect of 20,20,1,1.

You might still have to specify popoverContentSize.

Upvotes: 5

Related Questions