Reputation: 257
I am working with a tableview in editing mode. I am using the checkmark multi select method as you can see in the iOS built in mail edit mode -- also linked here.
My issue is that when a cell is selected, the background changes to the default tintColor.
My expected outcome is that the tableViewCell onSelect fills in the checkmark but does not change the background color.
I have tried changing the selectionStyle to .none -- this makes it so I cannot select the cell at all in editing mode. I have also tried changing the selected background view without success.
open override func viewWillLoad(withData data: Any!) {
self.view.backgroundColor = .gray
self.tableView = UITableView()
self.tableView.setEditing(true, animated: true)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.allowsMultipleSelection = true
self.tableView.allowsSelectionDuringEditing = true
self.view.addSubview(tableView)
}
public func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.init(rawValue: 3)!
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// dequeueing my cell here
cell.textLabel?.text = data[indexPath.row]
// cell.selectionStyle = ????
return cell
}
Is there any way to achieve this other than creating a custom button?
Upvotes: 1
Views: 1747
Reputation: 791
Try this:
func tableView(_ tableView: UITableView,
shouldHighlightRowAt indexPath: IndexPath) -> Bool {
return !tableView.isEditing
}
Upvotes: 0
Reputation: 257
It turns out that there is a specific background for tableViews that use Multiple Selection!
My solution was to use the following code on my cells:
let selectedView = UIView()
selectedView.backgroundColor = cellBackgroundColor
self.multipleSelectionBackgroundView = selectedView
self.selectionStyle = .default
If you are only using single selection you can use the following:
let selectedView = UIView()
selectedView.backgroundColor = cellBackgroundColor
self.selectedBackgroundView = selectedView
self.selectionStyle = .default
Upvotes: 3
Reputation: 369
You can remove that highlighted color in storyboard.
select selection to None
And also you can remove that color by code
cell.selectionStyle = .none
Upvotes: 0