Reputation: 17169
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.
Upvotes: 1
Views: 7188
Reputation: 684
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"));
}
Upvotes: 13
Reputation: 50119
TouchDown
- setSelected:animated: is called on the cell itself on touch down here, you can inform a cells delegate
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[self.delegate willSelectCell:self];
}
declare custom cells delegate as property of the cell
@property id<MyCellDelegate> delegate;
TouchUP
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
Upvotes: 1