Get UITableviewCell position from "visible" area or window

Mickael picture Mickael · May 8, 2011 · Viewed 20.7k times · Source

I create an iPhone app base on uitableview and uitabbar. On each cell of tableview i have an "add to favorite button". When i pressed this button, i want to make the cell "jump" from her position to the favorite item of the tabbar (same as download effect in installous)

The effect work well if i'am on top 10 cell, but if i scroll in the tableView the effect is not good because start position is calculate from uitableview size.

It's possible to know the position of a cell from the visible area. ?

Exemple : for the fortieth cell position is x:0,y:1600,w:320,y:50, i want the position from the top of the screen not from the top of the uiview so something like this x:0,y:230,w:320,y:50

Answer

Nick Weaver picture Nick Weaver · May 8, 2011

Yes you can use rectForRowAtIndexPath: you'll just have to pass in the indexPath of your row you've clicked.

rectForRowAtIndexPath:

Returns the drawing area for a row identified by index path.

...

EDIT

Conversion:

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