0

I'm working on a small MacOS app with a super simple NSTableView. When the user select a cell I need to know the column and the row index of this cell. I've implemented the method

- (void)tableViewSelectionDidChange:(NSNotification *)notification

and ask to the NSTableView for selectedColumn and selectedRow, but when I click on the table the result is always the selection of an entire Row. (in fact selectedRow return the right index number and selectedColumn return -1 = no selection)

How can I select a single Cell and how can I know his coordinates?

Thanks for any help!

The selected row

Grigno
  • 3
  • 1
  • `NSTableView` can select rows and columns but the user can't select a single cell. Do you want to get the column of the focused text field? – Willeke Jun 06 '18 at 14:55
  • Possible duplicate of [which method is called when selecting a cell in the NSTableView in Cocoa OS X?](https://stackoverflow.com/questions/10796724/which-method-is-called-when-selecting-a-cell-in-the-nstableview-in-cocoa-os-x) – koen Jun 06 '18 at 15:13
  • @Koen unfortunately in that question the programmer only ask for row number, but thanks for your comment – Grigno Jun 06 '18 at 22:27
  • @Willeke oh, unexpected! My intent was to crate a small and simple “ExcelStyle” table, where user can select a specific cell. I don’t even need to edit the cell content directly, I just need to know where the user want the program to place new data. Maybe NSTableView is not the right way? Do you have any suggestion? P.S. when program start I don’t know how many column and row the user needs so I add them programmatically at run time. Thanks for your comment! – Grigno Jun 06 '18 at 22:38
  • Maybe `NSCollectionView` is what you are looking for: https://developer.apple.com/documentation/appkit/nscollectionview?language=objc – koen Jun 07 '18 at 12:20
  • @Koen thanks! A customizable layout is perfect for my app! Thanks again for your help! – Grigno Jun 07 '18 at 14:24
  • Happy to help, and welcome to StackOverflow. For completeness, I wrote my comment in answer - if it solved your issue, please mark it as accepted. – koen Jun 07 '18 at 15:04

1 Answers1

0

For a grid or spreadsheet type layout it is better to use an NSCollectionView.

See the documentation for more info.

koen
  • 5,383
  • 7
  • 50
  • 89