Description:
In an iOS / iPad / tvOS / macOS application, under macOS it's impossible to pre-select several cells of the same UITableView.
Visually only one cell is checked and the tableView.indexPathsForSelectedRows property has always only one element.
Instruction:
Cells visually selected AND indexPathsForSelectedRows reflecting this selection
Obtained result:
Only the last cell called by tableview.selectRow is selected and present in the property indexPathsForSelectedRows
Did you find a solution to have cell preselected and have property indexPathsForSelectedRows representing the display ?
Thanks for your help !
In an iOS / iPad / tvOS / macOS application, under macOS it's impossible to pre-select several cells of the same UITableView.
Visually only one cell is checked and the tableView.indexPathsForSelectedRows property has always only one element.
Instruction:
Create a UITaleView with custom cell and several sections
tableView.allowsMultipleSelection = true
In the custom cell, overload setSelected to show a .checkmark or .none
In awakeFromNib of the custom cell define selectionStyle to .none
In cellForRowAt of the tableview define cells to pre-select, example first cell of each section:
Code Block if (indexPath.row == 0) { tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) } else { tableView.deselectRow(at: indexPath, animated: false) }
> Run
Cells visually selected AND indexPathsForSelectedRows reflecting this selection
Obtained result:
Only the last cell called by tableview.selectRow is selected and present in the property indexPathsForSelectedRows
Did you find a solution to have cell preselected and have property indexPathsForSelectedRows representing the display ?
Thanks for your help !