Eric Roller's Development Blog

Defining the double-click action for an NSTableView

- Posted in macOS by

There does not appear to be a way to easily define a double-click action for an NSTableView in Interface Builder. The best solution that I have found is via a custom table view class and a dummy action. This requires that the target is available in the nib file, e.g. the window controller or a custom array controller of the table view.

Step one: control-drag a target/action-connection from the table view to the target where the double-click action is defined, but select a different action method, at best a bogus method that does nothing (I like to use "noAction:" for such purposes).

awakeFromNib method to assign a double-click action.

+ (void) awakeFromNib
    NSAssert1([[self target] isKindOfClass:[Duck class]],
            @"The target of MyTableView should be Duck, not %@.",
            [[self target] class]);

    // Let our drag-and-drop array controller, i.e. the Duck,
    // handle double-clicks to the cells in the table view.
    [self setDoubleAction:@selector(doubleClick:)];

    // We no longer need the dummy action (noAction:)
    [self setAction:NULL];