I have a tableview that allows multiple selection. I have set both allowsMultipleSelection and allowsMultipleSelectionDuringEditing to true in viewDidLoad and this is working perfectly on both iOS and iPadOS. I have decided to try out the Catalyst today and the app looks good except that I cannot select multiple rows in this view. Any ideas? Here is the code below. Many thanks in advance.
//allow multiple selection
override func viewDidLoad()
{
super.viewDidLoad()
self.tableView.allowsMultipleSelection = true
self.tableView.allowsMultipleSelectionDuringEditing = true
.....
}
//limit selection to 7 rows
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if let selectedItems = tableView.indexPathsForSelectedRows {
if selectedItems.count > 6 {
return nil
}
}
return indexPath
}
@IBAction func doneButtonTapped(_ sender: UIBarButtonItem) {
...
let selectedIndexPaths = tableView.indexPathsForSelectedRows
if !selectedIndexPaths!.isEmpty {
for index in selectedIndexPaths! {
let selectedProcedure = fetchedResultsController?.object(at: index) as! Item
...
Rest of code to perform the required task
}
Multiple selection on macOS Catalyst does not work in quite the same way as on iOS and iPadOS and this appears to be either a bug or an unfortunate choice of intended behavior.
On macOS Catalyst, if you have enabled multiple selection in edit mode by setting tableView.allowsMultipleSelectionDuringEditing to true, only one row at a time can be directly selected by clicking with the pointer. However, multiple selection of contiguous rows is enabled by selecting a first row and then holding down SHIFT while selecting a second row, and multiple selection of non-contiguous rows is enabled by selecting a first row and then holding down COMMAND while selecting additional rows. This is Mac-like behavior in that it is how multiple selection generally works on macOS. So it is possible that this was intended behavior. But if that is the case, it is behavior that is hard to discover, not what an iOS/iPadOS user might expect, and works differently than on iOS and iPadOS. And it causes other problems - for example, in code I have a "Select All" function that is able to select all rows from code on iOS/iPadOS, and this code doesn't work on macOS Catalyst.
I filed Feedback on this. There is a simple project on GitHub at WB2ISS/MultipleSelection that demonstrates the problem.