I want to apply some style changes to a custom table view cell on highlight/select so am overriding isHighlighted
and isSelected
to achieve this. It works for my custom collection view cells but not when I tap on the custom table view cells.
I set up the exact same scenario for a table view and collection view and implemented the following on the custom cells:
override var isHighlighted: Bool {
didSet {
//called when I tap for CustomCollectionViewCell not for CustomTableViewCell
}
}
override var isSelected: Bool {
didSet {
//called when I tap for CustomCollectionViewCell not for CustomTableViewCell
}
}
What am I missing here? Why doesn't the table view cell did set get called when it's tapped? This happens for any table view I try with regardless of the content of the custom cell.
The other answer did not work for me. I reckon the reason is that UITableViewCell.isSelected
setter is never called when the containing UITableView
handles selection, that state is passed via func setSelected(_ selected: Bool, animated: Bool)
instead. This means that overriding this function in your UITableViewCell
subclass instead of the setter works:
override func setSelected(_ selected: Bool, animated: Bool) {
// implementation that was meant to be in `isSelected` `didSet`
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With