感谢其他人指路。我无法让窗口的默认字段编辑器使用任何委托方法。最后,我将以下内容放入窗口委托的 -windowDidLoad 方法中
NSTextView* defaultFieldEditor = [self.window fieldEditor:YES forObject:nil];
// defaultEditor.delegate = self; didn't help
NSMenu *mu = defaultEditor.menu;
[mu insertItem:[NSMenuItem separatorItem] atIndex:0];
[mu insertItemWithTitle:@"Insert Line"
action:@selector(acnInsertLine:)
keyEquivalent:@"" atIndex:0];
[mu insertItemWithTitle:@"Delete Line"
action:@selector(acnDeleteLine:)
keyEquivalent:@"" atIndex:0];
这应该将项目放在开头(所以相反的顺序)。你可以addItem:
改用。两者都存在菜单内容不同的问题,并且您的项目可能位于中间的某个位置。
请注意,即使它覆盖的控件是 NSTextField,字段编辑器也是 NSTextView。这让我有些困惑。