[英]UITableViewCell subview disappears on selection(But the contents within this subview are visible)
This is the .m file of my UITableViewCell. 这是我的UITableViewCell的.m文件。
#import "ContentCardTableViewCell.h"
#import <QuartzCore/QuartzCore.h>
@implementation ContentCardTableViewCell
- (void)awakeFromNib {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
[self setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected) {
[self setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}
}
@end
But one view in this UITableViewCell disappears on selection. 但是这个UITableViewCell中的一个视图在选择时消失了。 I have tried this and this and many more but nothing helped.
我曾尝试这个和这个 ,还有更多,但没有任何帮助。 Is there something I am missing?
有什么我想念的吗?
I had a similar issue. 我有一个类似的问题。
If i set selectionStyle to UITableViewCellSelectionStyleNone works fine, problem solved. 如果我将selectionStyle设置为UITableViewCellSelectionStyleNone工作正常,问题解决了。 ie;
即;
in the 在里面
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
add 加
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
before returning the cell.Hope it works. 在返回牢房之前。希望它有效。
you forgot to recover state after deselecting of cell 取消选择细胞后,你忘了恢复状态
if (selected) {
[self.contentView setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}else{
[self.contentView setBackgroundColor:[UIColor whiteColor]]
}
PS: it's preferred to setup color of cell.contentView PS:首选设置cell.contentView的颜色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.