[英]UITableViewCell subview disappears on selection(But the contents within this subview are visible)
這是我的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
但是這個UITableViewCell中的一個視圖在選擇時消失了。 我曾嘗試這個和這個 ,還有更多,但沒有任何幫助。 有什么我想念的嗎?
我有一個類似的問題。
如果我將selectionStyle設置為UITableViewCellSelectionStyleNone工作正常,問題解決了。 即;
在里面
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
加
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
在返回牢房之前。希望它有效。
取消選擇細胞后,你忘了恢復狀態
if (selected) {
[self.contentView setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}else{
[self.contentView setBackgroundColor:[UIColor whiteColor]]
}
PS:首選設置cell.contentView的顏色
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.