相关疑难解决方法(0)

Cocoa:右键单击NSStatusItem

我是一名.Net开发人员,他需要将一个小项目移植到Mac中,所以我对Objective C几乎一无所知.事实上,下面的代码只是抓住了一堆稻草,在黑暗中拍摄.

尝试构建一个状态菜单程序,打开一个或另一个窗口,具体取决于它是左键单击还是右键单击/按住Ctrl键单击.这是我所拥有的,它仅适用于左键单击(显然):

-(void) awakeFromNib{

    NSBundle *bundle = [NSbundle mainBundle];

    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
    [statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
    [statusItem setImage:statusImage];
    [statusItem setToolTip:@"Program Name"];
    [statusItem setHighlightMode:YES];
    [statusItem setAction:@selector(openWin:)];
    [statusItem setTarget: self];
}

-(void)openWin:(id)sender{
    [self openLeftWindow:sender];
}

-(IBAction)openLeftWindow:(id)sender{
    //Code to populate Left Click Window
    [leftWindow makeKeyAndorderFront:nil];
}

-(IBAction)openRightWindow:(id)sender{
    //Code to populate Right Click Window
    [rightWindow makeKeyAndorderFront:nil];
}
Run Code Online (Sandbox Code Playgroud)

在我看来,解决方案将是openWin()函数中的if语句,以确定单击哪个按钮(或者如果按住ctrl)然后运行相应的代码或使菜单知道左右两侧点击.但是当我试图这样做时,这些都没有奏效.

提前致谢.

cocoa right-click nsstatusitem

9
推荐指数
1
解决办法
7396
查看次数

标签 统计

cocoa ×1

nsstatusitem ×1

right-click ×1