【问题标题】:UITableViewCell subview disappears on selection(But the contents within this subview are visible)UITableViewCell 子视图在选择时消失(但此子视图中的内容可见)
【发布时间】:2015-06-08 10:38:01
【问题描述】:

这是我的 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 中的一个视图在选择时消失了。我试过thisthis 等等,但没有任何帮助。有什么我遗漏的吗?

【问题讨论】:

    标签: ios objective-c iphone uitableview


    【解决方案1】:

    我遇到了类似的问题。
    如果我将 selectionStyle 设置为 UITableViewCellSelectionStyleNone 工作正常,问题就解决了。 即;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    添加
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    在返回单元格之前。希望它有效。

    【讨论】:

      【解决方案2】:

      取消选择单元格后忘记恢复状态

      if (selected) {
          [self.contentView setBackgroundColor:[UIColor clearColor]];
      // Recover backgroundColor of subviews.
      }else{ 
          [self.contentView setBackgroundColor:[UIColor whiteColor]]
      }
      

      PS:最好设置cell.contentView的颜色

      【讨论】:

        猜你喜欢
        • 2011-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-01
        相关资源
        最近更新 更多