开发者

Enable copy for selected rows in NSTableView

I've read through Cocoa Programming for Mac OS X by Aaron Hillegass about how to do Copy/Paste, but I can't get it to work for an NSTableView.

My NSWindowController has a window with a couple of textfields and an NSTableView. When the textfields have focus, the Copy menu is enabled and I can copy the values (which is all defaul开发者_Go百科t behavior, no action/code on my part was required).

My NSWindowController has a -copy: method implemented and declared:

- (void) copy:(id)sender {
    NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
    // some code to put data on the pasteBoard
}

However, when I select a few rows and try to Copy, the copy menu is not enabled and I cannot copy the selected rows.

Is there something else I need to do to enable copy for my NSTableView?


The problem ended up being that my window's delegate wasn't set to be my window controller, so when the window was trying to validate the menu items it didn't know who to check for selectors.


inside the interface builder, make sure that the save menu's selector is connected to the first responder's "save:" action

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜