Reputation: 372
I have UIImageView
in a custom TableViewCell
. I load an image in it with this code:
UIImageView *myImg = (UIImageView *)[cell viewWithTag:kImagePlayer];
myImg.image = [UIImage imageNamed:@"player_play.png"];
So my question is how to change this image when I touch the row? I need to change the image to "music_play".
Thanks!
Upvotes: 1
Views: 2568
Reputation: 12335
You need to check which row was selected using the tableView:didSelectRowAtIndexPath
method and find the row selected using
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
Then you set the new image to it.
Upvotes: 0
Reputation: 2256
Hi I think this will help
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *tempCell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
UIImageView *myImg = (UIImageView *)[tempCell viewWithTag:kImagePlayer];
myImg.image = [UIImage imageNamed:@"music_play.png"];
}
BR, Hari
Upvotes: 0
Reputation: 3588
In tableView:didSelectRowAtIndexPath:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIImageView *myImg = (UIImageView *)[cell viewWithTag:kImagePlayer];
myImg.image = [UIImage imageNamed:@"player_play.png"];
Upvotes: 3