Reputation: 26355
I have a view-based NSTableView containing a list of words. When the user double-clicks on a word, I would like to take an action. The words are not editable or selectable. How do I do this?
I have tried setting the target and action of the table view in IB, but it only calls the action method when the user clicks in the header of the table, not in one of the words.
I have tried setting the target and action of the NSTextField that the table cell view keeps in IB. This results in this error message being repeated in the console:
2018-01-02 14:14:32.080347-0800 WordExplorer[7089:21457459] Could not connect action, target class NSObject does not respond to -relatedWordClick:
However the target class does respond to the selector. (I connected it in IB directly, so clearly, it does!) It is also not a simple NSObject
, so I'm guessing that something else is going wrong there.
I have tried manually calling -setTarget:
and -setAction:
on the NSTextField
contained in the table cell view in my delegate's -tableView:viewForTableColumn:row:
method. This has no effect, and the debugger shows that despite calling those methods, they do not set the text field's action or target method. (Though, given this is Xcode we're talking about, it's likely that's just a debugger display issue.) I get no errors in the console like when I make the connection in IB, but it also does not call the appropriate method.
Do I need to make custom view class and use that for the table cell view? Or is there a simpler way to get clicks (and preferably double-clicks) on words in my list?
Upvotes: 0
Views: 62
Reputation: 17050
Simply create an IBAction
on the object you have as the NSTableView
's target
, and then set the NSTableView
's doubleAction
property to the selector for that IBAction
, and you can handle double-click events easily.
Upvotes: 2