问题
I'm using Xcode 11 beta 6, on selecting the UITableViewcell ,cell has not been highlighted.It has a white background instead of showing selected background color.
回答1:
Per iOS 13 release notes (https://developer.apple.com/documentation/ios_ipados_release_notes/ios_ipados_13_beta_8_release_notes) - The UITableViewCell class no longer changes the backgroundColor or isOpaque properties of the contentView and any of its subviews when cells become highlighted or selected.
The UITableViewCell class no longer changes the backgroundColor or isOpaque properties of the contentView and any of its subviews when cells become highlighted or selected. If you are setting an opaque backgroundColor on any subviews of the cell inside (and including) the contentView, the appearance when the cell becomes highlighted or selected might be affected. The simplest way to resolve any issues with your subviews is to ensure their backgroundColor is set to nil or clear, and their opaque property is false. However, if needed you can override the setHighlighted(:animated:) and setSelected(:animated:) methods to manually change these properties on your subviews when moving to or from the highlighted and selected states.
回答2:
This works for me for iOS13 device that build with Xcode11.1
Objective-c
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.contentView.backgroundColor = [UIColor clearColor];
}
Swift
cell.contentView.backgroundColor = UIColor.clearColor()
回答3:
The following solution worked for me.
I had to assign clearColor to contentView of my cell.
cell.contentView.backgroundColor = [UIColor clearColor];
Then assign a background view to cell when selected. I added below code in my
cellForRowAt:
method:UIView *test = [[UIView alloc] init]; test.backgroundColor = [UIColor colorWithRed:213.0f/255.0f green:239.0f/255.0f blue:222.0f/255.0f alpha:1.0f]; your_Cell.selectedBackgroundView = test;
来源:https://stackoverflow.com/questions/57697830/uitableview-selected-cell-color-is-not-rendered-in-ios13