Get Cell position in UITableview

To get the position of a UITableViewCell relative to the view, in which the tableView is located (e.g. relative to your visible area):

Swift 5 (and also Swift 4, Swift 3):

let rectOfCellInTableView = tableView.rectForRow(at: indexPath)
let rectOfCellInSuperview = tableView.convert(rectOfCellInTableView, to: tableView.superview)
    
print("Y of Cell is: \(rectOfCellInSuperview.origin.y)")

Objective-C:

CGRect rectOfCellInTableView = [tableView rectForRowAtIndexPath: indexPath];
CGRect rectOfCellInSuperview = [tableView convertRect: rectOfCellInTableView toView: tableView.superview];

NSLog(@"Y of Cell is: %f", rectOfCellInSuperview.origin.y);

Swift 2 (really?):

let rectOfCellInTableView = tableView.rectForRowAtIndexPath(indexPath)
let rectOfCellInSuperview = tableView.convertRect(rectOfCellInTableView, toView: tableView.superview)

print("Y of Cell is: \(rectOfCellInSuperview.origin.y)")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)