在UITablView单元的选定状态下更改图像 [英] Changing Image on selected state of UITablView cell

查看:107
本文介绍了在UITablView单元的选定状态下更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义单元格并添加了一个标签和图像,我在表格中有4行,每行有不同的图像,每行打开一个不同的视图控制器,所以,现在我需要的是点击一个特别的一行,我希望图像改变,我尝试这样做,但它不起作用,所以请帮助我。

I have a created a custom cell and added one label and Image, I have 4 rows in my table each row has a different image and each row opens a different view controller, so, now what I need is on click of a particular row I want the image to change to do that I tried this, but its not working, so please help me out.

if(indexPath.row == 0)
{

     if(cell.selected == true)
     {
           UIImage *cellImage = [UIImage imageNamed:@"abc.png"];        
           cell.icon.image    = cellImage;
      }
      else
      {
          UIImage *cellImage = [UIImage imageNamed:@"abc.png"];        
           cell.icon.image    = cellImage;
      }
}

问候
Ranjit

Regards Ranjit

推荐答案

在创建单元格时或在 tableView中尝试执行以下操作:willDisplayCell:forRowAtIndexPath:方法:

Try to do following when creating your cell or in tableView:willDisplayCell:forRowAtIndexPath: method:

cell.imageView.image = [UIImage imageNamed:@"abc.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:@"abc.png"];

它也适用于您的图标属性如果它是 UIImageView

It will work for your icon property too if it is UIImageView

这篇关于在UITablView单元的选定状态下更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆