我正在以编程方式构建NSMenu而没有任何Nib 请看一下这段代码:
self.editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
[self.editMenu addItemWithTitle:NSLocalizedString(@"Undo", nil)
action:@selector(undo:)
keyEquivalent:@"z"];
[self.editMenu addItemWithTitle:NSLocalizedString(@"Redo", nil)
action:nil
keyEquivalent:@"Z"];
[self.editMenu addItem:[NSMenuItem separatorItem]];
[self.editMenu addItemWithTitle:NSLocalizedString(@"Cut", nil)
action:@selector(cut:)
keyEquivalent:@"x"];
[self.editMenu addItemWithTitle:NSLocalizedString(@"Copy", nil)
action:@selector(copy:)
keyEquivalent:@"c"];
[self.editMenu addItemWithTitle:NSLocalizedString(@"Paste", nil)
action:@selector(paste:)
keyEquivalent:@"v"];
如您所见,有@selector(cut:)
,@selector(copy:)
和@selector(paste:)
。但是没有@selector(undo:)
和@selector(paste:)
。编译器说“Undeclared selector”undo:'。
如何以编程方式实现撤消和重做菜单项的操作?