12

So, I have this UITableView. It's in an iPad application. Some of the cells have an accessory button on the right (the small round arrow). When that is pressed, I present a popover view where the user can select actions related to the table cell that they touched. So far, nothing of this is difficult or exceptional.

But the popover view wants to know where it originates from, so that it can draw the little arrow pointing there. I would naturally like that arrow to point at the table cell the popover relates to.

How can I find out the current on screen coordinates for a certain cell in a table, given that I know it's indexPath?

Jakob Borg
  • 23,685
  • 6
  • 47
  • 47

1 Answers1

31

Use the UITableView method -rectForRowAtIndexPath:. Note that that returns a rect within the table view’s coordinate system—if you need the rect relative to another view within the same window, use the UIView method -convertRect:fromView:.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • 4
    My God, it's so simple! I must have been looking in all the wrong places. – Jakob Borg Aug 03 '10 at 19:35
  • 2
    Careful with that one, if the UITableCell is off screen below, it will give you the y coordinate for it within the table view not the actual screen coordinate. Otherwise this method works great! – TChadwick Sep 07 '12 at 00:23
  • This method only gives you the offset from the scrollview, the tableview contains. So you'll get the right size but if your tableView it not located at the top of your view, it will not calculate this. Event if you scroll down, this method won't respect that. – Julian F. Weinert Jan 14 '13 at 18:53
  • 3
    The method returns the cell’s frame in the table view’s coordinate system, yes. That’s why there are methods like `-convertRect:fromView:`. – Noah Witherspoon Jan 14 '13 at 19:24
  • There is also a `rectForSection` if it helps – Hola Soy Edu Feliz Navidad Apr 21 '16 at 12:16