Search code examples
swifttvosuitableview

tvOS custom UITableViewCell with UIView losing background in selected state


I have simple tvOS application with UITableView with custom UITableViewCell that have inside UIView. Strange thing is happening when cell is selected (not focused, have to be selected) then UIView is becoming invisible (partially as I discover later by setting border to the UIView) Image below shows the problem:

UIView lose background in selected state

I tested that when create subclass from UITableViewCell and override func setHighlighted where I reset background value then UIView will be again "visible"


Solution

  • In the selected state set the background colour of the view again, this happens in iOS as well as tvOS:

    - (void)setSelected:(BOOL)selected;
    

    and

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;