UITableView controls are widely used in the development of iOS projects. When you do a custom UITableViewCell, you often encounter the problem of adding a sub-view with a background color on UITableViewCell, and when the user taps UITableViewCell or selects UITableViewCell, The child view on the cell has been strangely changed, its background color is transparent, and if the child view added to the cell is just a color block, then we look like this sub-view is somehow gone.
if set self.selectionstyle = Uitableviewcellselectionstylenone; This can also solve the problem.
But if you want to click on the cell to have a background color, the above method is useless. (Provides a way to set the background of the cell Self.selectedbackgroundview = [[UIView alloc] initWithFrame:self.frame]; Self.selectedBackgroundView.backgroundColor = [Uicolor Redcolor]), this time we only need to rewrite the cell's two parent class two methods, re-set the background color of the child view.
// This method is called when the cell is selected or unchecked-(void) setselected: (BOOL) selected animated: (bool) animated { [ Super setselected:selected animated:animated]; = [Uicolor bluecolor];} // This method is called when the user presses and holds the cell -(void) sethighlighted: (BOOL) highlighted animated: (BOOL) animated{ [ Super sethighlighted:highlighted animated:animated]; = [Uicolor bluecolor];}
Workaround for child view background transparency when IOS UITableViewCell clicked