Get absolute position of a UITableViewCell

Here’s something that helped me when I was working with WEPopover to implement a popover in my iPhone app a la the iPad.

If your popover is being instantiated from a UIViewController with a UITableView in it that does not fill up the whole window, then you may have some issues getting the popover to align properly.

To get the alignment to work, you need to get the UITableViewCell‘s absolute position on screen.

You can achieve that through the following code:


CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];

And then…

[self.popoverController presentPopoverFromRect:rectInSuperview
inView:self.view
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
animated:YES];

Thanks to Nick Weaver at this StackOverflow question for explaining this. Took some finding.

Up Next:

Waterloo Life

Waterloo Life