3

I am trying this solution also But It doesn’t solve my problem

Get selected column and row from NSTableView

Get selected row and column in view based nstable

How can I get the column selected ? what i get when i am using selectedColumn property of NSTableView

[tableView selectedColumn] //returns -1
[tableView selectedRow] //returns 1,

is there any way to get selected column

Note: I want to get selected column without creating subclass of NSTableView class

Community
  • 1
  • 1
Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38

2 Answers2

2

I had a similar problem, here is the link of my problem solved by Ken Thomases. I hope it could help you too!

Click here to see the problem solved: How do I select column and row from a NSTableView

In objective-C I think it should look like that

Community
  • 1
  • 1
Rafa Febrer
  • 184
  • 14
  • thanks for your answer but i am using objective c and your code in swift and i dont know much about swift, please can you explain about columnForView(sender) method or its equivalent in objective c – Sangram Shivankar Mar 19 '16 at 13:31
  • 2
    `[self.tableview rowForView:sender];` and the same with columns. I think should look like that, but i'm not an objective-c expert. (I added an image on my old answer) – Rafa Febrer Mar 19 '16 at 14:04
  • @RafaFebrer you sir, are a lifesaver. This should be the accepted answer. – Dmitry Serov Jun 06 '17 at 06:40
1

Assuming you want the column being edited:

id firstResponder = self.window.firstResponder;
if ([firstResponder isKindOfClass:[NSView class]])
    NSInteger column = [self.tableView columnForView:firstResponder];
Willeke
  • 14,578
  • 4
  • 19
  • 47