I am trying to check the location of a TableViewCell’s textLabel’s frame. (Eventually I will want to check if a tap is inside this frame).
MyCell *c = [self tableView:self.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@ is in rect: %@ ", c.textLabel.text, NSStringFromCGRect(c.textLabel.frame));
This gives me logs like:
984943658 is in rect: {{0, 0}, {0, 0}}
The name part works fine (the text is that number), but why is it giving me 0’s for the frame? I can see the text on screen, so it must be in a frame – why can’t I get it?
You call the
tableView:cellForRowAtIndexPath:method of the table view data source delegate. That creates a new table view cell.You probably want to call
which returns the cell at the index path (if it is visible).