I'm writing an application with Swift that's using an NSTableView as its main interface. The application presents information from a very large array just like a spreadsheet. How can I let the user select a single cell from the NSTableView?
I've read https://stackoverflow.com/a/20807563/2771733 which states:
It sounds like you're trying to make a spreadsheet. That's not what a table view is.
But there's no real solution provided other than "You're best off implementing a custom view" – which seems like a lot of work and is way beyond my current knowledge.
One idea I came across was to disable selecting at all and provide my own mouse handler but I wasn't able to switch off selecting. Even when unchecking all boxes in the Selection section in the Attribute Inspector for the Table View, a user can still select (highlight) a row. And that would interfere with my own mouse handle code.
So, is there any way to (ab)use a NSTableView as a spreadsheet? Or any other hints how I could let a user just select a single cell instead of a whole row?
Update: The answer to the possible duplicate question is just a single sentence recommending NSCollectionView for the task, but does not provide any reasons why. Especially my task to present "information from a very large array just like a spreadsheet" isn't addressed. For example, the NSCollectionViewDataSource protocol enforces you to implement collectionView:numberOfItemsInSection:
. But the notion of a (inherently one-dimensional) "number of items" doesn't fit well with the idea of a spreadsheet with its two-dimensional data. The same holds true for collectionView:itemForRepresentedObjectAtIndexPath:
where the index path gives you the item index within that section
. Again I have to deal with one-dimensional indices for a two-dimensional source.
What I'm looking for is a native solution for rather simple grid views other GUI toolkits provide like FLTK's Fl_Table or wxWidget's wxGrid.