我有带有原型(prototype)单元的表格 View ,其右侧有 2 个标签和图像。
目前,如果我有 10 行数据,我会在每一行上看到图像。但是我只想看到选定行上的图像,而不是全部。
因此,一旦我选择一行,我就希望出现图像
有人可以指导我如何在 Swift 中完成这个任务吗?
我想也许最初我可以在属性检查器中禁用它,一旦选择一行,仅对该行启用它,不知道如何做到这一点。
最佳答案
您可以实现以下代码来实现该目标
@implement CustomCell
- (void)awakeFromNib {
[super awakeFromNib];
[_imagevw setHidden:YES];
[_imageTopConstraint setActive:NO];
[_imageBottomConstraint setActive:NO];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[_imageTopConstraint setActive:YES];
[_imageBottomConstraint setActive:YES];
}
@end
如果一切设置正确,上面的行就可以解决问题。
您的表格 View rowHeight
应该是UITableViewAutomaticDimension
和estimatedRowHeight
并使用默认值
关于ios - 在选定的表格行上启用图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37289442/