UIView backgroundColor disappears when UITableViewCell is selected

前端 未结 17 1027
谎友^
谎友^ 2020-11-30 17:49

I have a simple tableViewCell build in interface builder. It contains a UIView which contains an image. Now, when I select the cell, the default blue selection background is

17条回答
  •  攒了一身酷
    2020-11-30 18:20

    In iOS 7, what worked for me is to override setSelected:animated: in the UITableViewCell subclass, but contrary to @Brooks' tip, I called [super setSelected:selected animated:animated].

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];
    
        // Reassert the background color of the color view so that it shows
        // even when the cell is highlighted for selection.
        self.colorView.backgroundColor = [UIColor blueColor];
    }
    

    This lets me keep the system's default selection animation when the user taps on the cell, and also to deselect it in the table view delegate's didSelectRowAtIndexPath:.

提交回复
热议问题