2006-06-19

Table view double-click actions

It used to be that when you wanted to receive a double-click notification from an NSTableView, you had to do this in your -awakeFromNib:

[tableView setTarget:self]; [tableView setDoubleAction:@selector(doMagicThings:)];

Now, with the power of Bindings, you can do this in IB!

  1. Create an NSObjectController. Set its class name to the class of the desired receiver, and its “content” outlet (not binding) to the desired receiver.
  2. Bind the table view's doubleClickTarget binding to the object controller. Controller key: content. Leave the model key path empty.
  3. Put the selector name in the field at the bottom of the binding view.

And a cheesy way that doesn't involve a controller:

  1. Add a method named -self to your receiver's class (or to NSObject) that simply returns self.
  2. Bind the table view's doubleClickTarget binding directly to the receiver. Model key path: self.
  3. Put the selector name in the field at the bottom of the binding view.

Technorati tags: Cocoa, NSTableView.

0 comments:

Post a Comment

<< Home