Take the 2-minute tour ×

I need to get the the currently selected UITableViewCell as its tapped. So upon my finger touching the screen/cell I want to run a method from which I can say something as simple as:

selectedCell = cell;

cell being the one I just tapped and selectedCell being a copy I store.

I am using a custom subclassed UITableViewCell which is why I think I'm having trouble, but if you could help me find a way of doing this I would much appreciate it, thanks.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

- setSelected:animated: is called on the cell itself on touch down here, you can inform a cells delegate

   [self.delegate willSelectCell:self];

declare custom cells delegate as property of the cell

@property id<MyCellDelegate> delegate;

save the cell in the delegate

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_selectedCell = [aTableView cellForRowAtIndexPath:indexPath];

just pay attention to the fact that Cell Views can be reused

share|improve this answer
I figured this might be suggested, sorry I didn't mention, but possibly because of my custom cell, this doesn't get called on pressing my cell. Would having a custom cell make any difference to this? –  Josh Kahane Dec 6 '12 at 17:09
Isn't didSelectRowAtIndexPath: get triggered on touch up? –  dasblinkenlight Dec 6 '12 at 17:10
@dasblinkenlight likely, sorry –  Daij-Djan Dec 6 '12 at 17:13
I've set a breakpoint in my cell subclass in the setSelected method and its never called when I tap my cells at all. –  Josh Kahane Dec 6 '12 at 17:18
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { NSLog(@"%@", self); } -- works fine in a custom subclass –  Daij-Djan Dec 6 '12 at 17:22
show 4 more comments

Just implement setHighlighted:animated: method on your own custom tableview cell like this.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];

    NSLog (@"setHighlighted:%@ animated:%@", (highlighted?@"YES":@"NO"), (animated?@"YES":@"NO"));
share|improve this answer
add comment

Your Answer


