我有一个 UITableView
,其中每个单元格都包含一个产品的 UIImageView
(异步加载但始终具有纯白色背景)和一个 UILabel
。当我单击它时,选定的单元格会突出显示,但 UIImageView
不会突出显示。我知道有这个属性
imageView.highlightedImage = [UIImage imagedNamed:@"product_highlighted"];
但很明显这仅适用于静态图像,而在本例中,我使用的是动态图像,因此在加载图像之前我没有图像。
我该如何解决这个问题?
最佳答案
您应该创建自定义 UITableViewCell
子类并覆盖 setHighlighted:animated
:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
[imageView setHighlighted:highlighted];
}
来自Apple docs :
Note that for highlighting to work properly, you must fetch the cell’s label (or labels) using the textLabel (and detailTextLabel properties and set the label’s highlightedTextColor property; for images, get the cell’s image using the imageView property and set the UIImageView object’s highlightedImage property.
关于ios - 选择单元格时,UITableViewCell 中的 UIImageView 未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917351/