-(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];
}