这是我的示例类和用法:
@interface CCocoaMenuItem : NSMenuItem
{
someClass *someobj;
}
- (void)menuEventHandler:(id)target;
- (void)setEnableItem:(BOOL)nEnabled;
@end
@implementation CCocoaMenuItem
- (BOOL)validateMenuItem:(NSMenuItem *)item {
// return YES or NO based on some conditions;
// But this method is not getting called
}
@end
CCocoaMenuItem *dummyItem = [[CCocoaMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:(NSString*)aStr action:nil keyEquivalent:@""] autorelease];
[dummyItem setAction:@selector(menuEventHandler:)];
[dummyItem setTarget:dummyItem];
这里 validateMenuItem 没有被调用。我已经设定了行动和目标。Target 是这个类对象本身,我只在这个类中定义了 validatemenuItem。
我在这里有什么遗漏吗?