Search code examples
iosipadtableview

How to convert a cell's frame's origin in terms of the view controller containing the tableview?


I have a TableView in a ViewController, when I select a cell, I want to check if its below a certain y limit.

that y limit is in terms of the view of the viewController.

I took cell's origin and converted it in terms of ViewController's view. Here I have used the method of UIView class : convertPoint:fromView:

Here I have passed tableView itself as the fromView parameter considering it is the direct parent view of a cell and the frame of the cell will be interms of the tableView.

I see some increase in the y-value of the new point that I get than what I should have been getting.

Is there a better way to achieve this ?


Solution

  • CGRect rectOfCellInTableView = [tableView rectForRowAtIndexPath:indexPath];
    CGRect rectOfCellInSuperview = [tableView convertRect:rectOfCellInTableView toView:[tableView superview]];
    
    NSLog(@"cell rect is : %@",NSStringFromCGRect(rectOfCellInSuperview));