I trying to port my iOS
app to macOS
using Catalyst
, but no matter what the UITableViewCellSelectionStyle.gray
style visually show the .blue
highlight, while the .style
value still prints .gray
.
I tried to force reset it in the following functions but with no luck.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath?
No matter what, it goes back .blue
from .gray
. If its .none
, it stays .none
.
Possible workaround was to set a background color manually, which feels like not right.
The blue color was from the focused state, so you will need to override the canBecomeFocused
property in your UITableViewCell subclass
override var canBecomeFocused: Bool {
return false
}
The default way of setting the selection style on Mac Catalyst did not work for me:
cell.selectionStyle = .gray
On the Mac Catalyst app the selection showed first gray then on the next click blue. To work around it I applied @Laszlo's solution. However you don't need a custom UITableViewCell. You can create a custom background view and set the .selectedBackgroundView
property of the UITableViewCell
instance to a custom background view.
let customSelectionBackgroundView = UIView()
customSelectionBackgroundView.backgroundColor = UIColor.red
cell.selectedBackgroundView = customSelectionBackgroundView
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