-(void)rightMouseDown:(NSEvent *)theEvent
{
cvcont = [[CollectionViweItemSubClass alloc] init ];
NSMenu * m = [[NSMenu alloc] init];
//[cvcont openInFinder];----perfectly working------
[self setTarget:cvcont];
[m addItemWithTitle:@"show in finder" action:@selector(openInFinder) keyEquivalent:@""];// not working-----
[NSMenu popUpContextMenu:m withEvent:theEvent forView:self];
}
我将按钮子类化并从类中调用方法 CollectionViweItemSubClass
。如果我像往常一样打电话,它正在工作。但该方法未通过 连接NSMenu
。下面的代码是我在 CollectionViewItemSubClass 类中的方法
-(void)openInFinder {
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"filePath"];
[[NSWorkspace sharedWorkspace] selectFile:savedValue inFileViewerRootedAtPath:nil];
}