Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverController presentPopoverFromRect problem

I am trying to present a UIPopoverController when a UIButton is clicked. Here's my code:

- (IBAction)showColumnChooser:(id)sender {

    ColumnChooserTVC *vc = [[ColumnChooserTVC alloc] init];

    [vc setSelections:allColumns];
    [vc setDelegate:self];
    UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];


    [pc presentPopoverFromRect:[sender frame] inView:self.view 
      permittedArrowDirections:UIPopoverArrowDirectionAny 
                      animated:YES];
    [vc release];
}

With the arrow direction as "Any", it completely obscures the button, here's what it looks like: enter image description here

If I make the direction "Right", it's a little better but still there's some room between the popover and the button and it doesn't seem right. enter image description here I don't want to do some "tricks" or "hacks" and use a CGRect on a trial/error basis, I want to know what's the proper way of doing this? Thanks.

Here's the button in interface builder as requested by Neckto: enter image description here

like image 355
0xSina Avatar asked Sep 04 '11 10:09

0xSina


1 Answers

I think you are mixing coordinate systems. At each level in your view-hiearchy, the origin is moved. So the location of [sender frame] in self.view is not where the button is located.

Try:

[pc presentPopoverFromRect:[sender bounds]
                    inView:sender
  permittedArrowDirections:UIPopoverArrowDirectionAny 
                  animated:YES];
like image 160
Mats Avatar answered Oct 05 '22 23:10

Mats