I have a SwiftUI view which contains an NSTableView wrapped with an NSViewControllerRepresentable struct. This has a Coordinator, which I set up as the NSTableView's delegate. There is an implementation of tableViewSelectionDidChange to pass the selected row index up to the enclosing view.
The problem is that I can click and select a row, but the selection disappears, usually on the first click, and always when clicking a column header to sort. I have looked at the various delegate methods for notifying about selection changing, and they don't seem to be called.
How can I find where the selection is being changed?
The problem is that I can click and select a row, but the selection disappears, usually on the first click, and always when clicking a column header to sort. I have looked at the various delegate methods for notifying about selection changing, and they don't seem to be called.
How can I find where the selection is being changed?
I never got an answer, but I solved my problem by redesigning the table to be expressible as a SwiftUI List, which does away with the awkward interaction with NSTableView. I got a cleaner design in some ways, but I lost a couple of things, particularly the ability to shade alternate rows to make it easier to read, and sorting by columns. Neither is a show-stopper, so I'm going with what I've come up with.