UICollectionViewCell Selected State Won't Highlight the Cell

Hi,

I'm using a UICollectionViewCell in my project and I can't wrap my head around why cell's UI state isn't changing when selected.

This is my code:

override func updateConfiguration(using state: UICellConfigurationState) {
        super.updateConfiguration(using: state)
        
        var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)
        
        background.cornerRadius = 25

        // Update background based on selection state
        if state.isSelected {
            background.backgroundColor = .systemBlue.withAlphaComponent(0.3)
            background.strokeColor = UIColor.systemBlue
            background.strokeWidth = 1.5
        } else {
            background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background
            background.strokeColor = UIColor.borderColor
            background.strokeWidth = 1
        }
        
        backgroundConfiguration = background
    }

The if block does get executed but it's not working for some reason. On the other hand, the else block works just fine, my cell's background is being highlighted when hovered over, the stroke is showing etc.

What am I missing here?

Thank you.

override func updateConfiguration(using state: UICellConfigurationState) { super.updateConfiguration(using: state)

    var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)
    
    background.cornerRadius = 25

    // Update background based on selection state
    if state.isSelected {
        background.backgroundColor = .systemBlue.withAlphaComponent(0.3)
        background.strokeColor = UIColor.systemBlue
        background.strokeWidth = 1.5
    } else {
        background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background
        background.strokeColor = UIColor.borderColor
        background.strokeWidth = 1
    }
    
    backgroundConfiguration = background
}override func updateConfiguration(using state: UICellConfigurationState) {
    super.updateConfiguration(using: state)
    
    var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)
    
    background.cornerRadius = 25

    // Update background based on selection state
    if state.isSelected {
        background.backgroundColor = .systemBlue.withAlphaComponent(0.3)
        background.strokeColor = UIColor.systemBlue
        background.strokeWidth = 1.5
    } else {
        background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background
        background.strokeColor = UIColor.borderColor
        background.strokeWidth = 1
    }
    
    backgroundConfiguration = background
}
var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)

background.cornerRadius = 25

// Update background based on selection state
if state.isSelected {
    background.backgroundColor = .systemBlue.withAlphaComponent(0.3)
    background.strokeColor = UIColor.systemBlue
    background.strokeWidth = 1.5
} else {
    background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background
    background.strokeColor = UIColor.borderColor
    background.strokeWidth = 1
}

backgroundConfiguration = background

}override func updateConfiguration(using state: UICellConfigurationState) { super.updateConfiguration(using: state)

var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)

background.cornerRadius = 25

// Update background based on selection state
if state.isSelected {
    background.backgroundColor = .systemBlue.withAlphaComponent(0.3)
    background.strokeColor = UIColor.systemBlue
    background.strokeWidth = 1.5
} else {
    background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background
    background.strokeColor = UIColor.borderColor
    background.strokeWidth = 1
}

backgroundConfiguration = background

}

var background = UIBackgroundConfiguration.listGroupedCell().updated(for: state)

background.cornerRadius = 25

// Update background based on selection state if state.isSelected { background.backgroundColor = .systemBlue.withAlphaComponent(0.3) background.strokeColor = UIColor.systemBlue background.strokeWidth = 1.5 } else { background.backgroundColor = isHoveredOver ? .hoverHighlightBackground : .background background.strokeColor = UIColor.borderColor background.strokeWidth = 1 }

backgroundConfiguration = background

UICollectionViewCell Selected State Won't Highlight the Cell
 
 
Q