为 NSTableView 中的选定行启用复制
我已经阅读了 Aaron Hillegass 的《Cocoa Planning for Mac OS X》,了解如何进行复制/粘贴,但我无法让它适用于 NSTableView。
我的 NSWindowController 有一个带有几个文本字段和一个 NSTableView 的窗口。当文本字段获得焦点时,将启用“复制”菜单,我可以复制这些值(这都是默认行为,我不需要任何操作/代码)。
我的 NSWindowController 有一个 -copy: 方法实现并声明:
- (void) copy:(id)sender {
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
// some code to put data on the pasteBoard
}
但是,当我选择几行并尝试复制时,复制菜单未启用,我无法复制所选行。
我还需要做些什么才能为我的 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 default 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题最终是我的窗口的委托没有设置为我的窗口控制器,因此当窗口尝试验证菜单项时,它不知道要检查谁的选择器。
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