Вопрос

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!

Это было полезно?

Решение

In tableView:didSelectRowAtIndexPath:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIImageView *myImg = (UIImageView *)[cell viewWithTag:kImagePlayer];
myImg.image = [UIImage imageNamed:@"player_play.png"];

Другие советы

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

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top