Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Adding more basic information to @JimPuls answer for the benefit of other newcomers to Cocoa.</p> <ol> <li>An IBOutlet to the NSTableView needs to be declared in an interface. I assumed it is preferred to do so in the table's delegate.</li> <li>The IBOutlet to the table needs to be connected via Interface Builder. To do that Ctrl-Drag &amp; Drop in IB from the class that declares the outlet to the table view. When you release your mouse a popup should appear with the name of the outlet you declared in step #1. Select that.</li> <li>In the @implementation section, on the -awakeFromNib method, call -setTarget: and -setDoubleAction: on the IBOutlet declared in step #1 and connected in step #2.</li> </ol> <p>Here's an excerpt from my table view delegate. I have my delegate also set up as the datasource, so that's why you'll see both the NSTableViewDelegate and NSTabeViewDataSource interfaces associated with it.</p> <p>// Interface excerpt.</p> <pre><code>@interface MyTableViewDelegate : NSObject &lt;NSTableViewDelegate, NSTableViewDataSource&gt; { // This iVar needs to be connected to the table view via the IB. IBOutlet NSTableView *tableOutlet; } @property (assign) IBOutlet NSTableView *tableOutlet; - (void)doubleClick:(id)nid; @end </code></pre> <p>// Implementation excerpt.</p> <pre><code>@implementation MyTableViewDelegate @synthesize tableOutlet = _tableOutlet; - (void)awakeFromNib { [_tableOutlet setTarget:self]; [_tableOutlet setDoubleAction:@selector(doubleClick:)]; } - (void)doubleClick:(id)object { // This gets called after following steps 1-3. NSInteger rowNumber = [_tableOutlet clickedRow]; // Do something... } </code></pre> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload