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:
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. 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:
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With