ios - 选择单元格时,UITableViewCell 中的 UIImageView 未突出显示

标签 ios objective-c uitableview uiimageview

我有一个 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/

相关文章:

iphone - 将 NSString 转换为 NSNumber

ios - 快速点击导航栏按钮,导致 View 被多次推送

ios - UITableView 更新时 View 发生变化

iphone - 什么可能导致崩溃?

iphone - 从头开始构建标签栏 View Controller

objective-c - Cocoapods 问题 : "How does cocoapods know when a new version of a library is available?" etc

iphone - 委托(delegate)没有从另一个 View Controller 调用,尝试了一切

iphone - CGImageCreateWithImageInRect 无法正常工作

iOS,自定义单元格中特定元素的alertView

ios - dequeueReusableCellWithIdentifier 的解决方法