3

I have a bunch of horizontal UITableView which is put inside a UIViewController1. I wanted to find the position of the UITableViewCell that is tapped, I wanted to get the position in terms of the UIViewController1. So here's what I did in didSelectRowAtIndexPath:

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];

                UIView *animatedView = [[UIView alloc] initWithFrame:cell.frame];
 [animatedView setFrame:[animatedView convertRect:animatedView.frame toView:self.newsRackController.view]];

However it seems that this doesn't convert it correctly. What am I doing wrong?

adit
  • 32,574
  • 72
  • 229
  • 373

2 Answers2

8

You need to convert the CGRect of the UITableViewCell from the UITableView's view and then convert it again to your view controllers view.

But instead of all that, perhaps you could just use UITableView's method

- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

Get this CGRect and convert it to your UIViewController's View.

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
1

It is because animatedView does not belong to any parents, and you are using frame as bounds. You should find the frame first and init animatedView accordingly.

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
CGRect animatedViewFrame = [tableView convertRect:cell.frame toView:self.newsRackController.view];
UIView *animatedView = [[UIView alloc] initWithFrame:animatedViewFrame];
tia
  • 9,518
  • 1
  • 30
  • 44