簡體   English   中英

UITableViewCell子視圖在選擇時消失(但此子視圖中的內容可見)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM