views:

390

answers:

1

I've been working on a menubar note-taking application for Mac. It is written in Objective-C and Cocoa, and I'm using BWToolkit with it. My problem is getting keyDown: and mouseDown: events in a BWTransparentTableView which is a subclass of NSTableView. I just can't get it to work. I've tried searching the Internet, and some places say that you must subclass NSTableView. I've tried that, but it still doesn't work. I am pretty new to Objective-C and Cocoa, and I may just be doing something incorrectly.

A: 

Items in an NSTableView will automatically begin editing when they are slow double-clicked or when the Return key is pressed. Make sure that the table view, the cell and the array controller (if used) are marked as editable.

If you are not using an NSArrayController, make sure that your table view has a delegate and that it responds to tableView:shouldEditTableColumn:row:.

To handle a double click, you just need to set the doubleAction of the table view:

- (void)awakeFromNib
{
    [tableView setTarget:self];
    [tableView setDoubleAction:@selector(doubleClickInTable:)];
}

- (void)doubleClickInTable:(id)sender
{
    NSInteger rowIndex = [sender selectedRow]; //Use selectedRowIndexes if you're supporting multiple selection
    //Handle the double click
}

Note that neither of these methods require you to subclass NSTableView.

Rob Keniger
Thank you! It worked perfectly. It's just that I read in the documentation that if a cell is editable, the doubleAction: isn't sent.
ausgat