我创建了一个自定义单元格并添加了一个标签和图像,我的表中有 4 行,每一行都有不同的图像,每一行打开不同的 View Controller ,所以,现在我需要的是单击特定行我希望更改图像以执行此操作,但它不起作用,所以请帮助我。
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;
}
}
问候 兰 git
最佳答案
在创建单元格时或在 tableView:willDisplayCell:forRowAtIndexPath:
方法中尝试执行以下操作:
cell.imageView.image = [UIImage imageNamed:@"abc.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:@"abc.png"];
如果它是 UIImageView
,它也适用于您的 icon
属性
关于ios - 在 UITableViewcell 的选定状态下更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10601966/