How can I get the frame of the table view cell in the coordinate space of the table view?

I have a tabular view with a bunch of cells in it. I want to get a cell frame, not in the coordinate space of the supervisor, but in the coordinate space of the table view.

The image will probably explain it better.

enter image description here

Look at the red rectangle? This is a table frame. And the blue rectangle is the frame of the table. I want to get a red rectangle relative to a blue rectangle.

I tried using the frame property of UITableViewCell . But this does not work because it returns (0, 0, 320, 44). The value of Y should not be zero, because, obviously, the cell is not at the top of the screen.

According to the hierarchy of views, this is the expected behavior, because the supervisor of the table cell is apparently a UITableViewWrapperView , not a table view:

enter image description here

while the table view is as follows:

enter image description here

So, is there a method / property that CGRect can get me that represents the frame of the table view cell in the coordinate space of the table view?

I think there is a function that can convert CGRect into a coordinate space into another. But I forgot his name and how to use it. I do not know if it is useful in this situation.

+5
source share
1 answer

Please use below code

 let rectOfCell= tableView.rectForRowAtIndexPath(indexPath) let rectOfCellInSuperview = tableView.convertRect(rectOfCell, toView: tableView.superview) 
+13
source

All Articles