当我点击它的menuItem的subMenu时,我怎么能让NSMenu不消失

时间:2016-12-10 08:57:39

标签: cocoa events nsmenu nsmenuitem nspopover

我定制了一个NSMenu,我设置了NSMenuItem的Action,当我点击NSMenuItem时它会显示一个NSPopover。我需要在NSPopover上做点什么,但是当我点击NSPopover时NSMenu会消失,我应该怎么做才能使NSPopover存在直到我完成NSPopover上的事情,换句话说,我怎样才能控制NSMenu的消失事件。谁能给我一些建议?谢谢!

以下是一些代码:

NSMenuItem *deadTimeLineItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"" action:@selector(showCalendarAction:) keyEquivalent:@""];
[self setAutoenablesItems:NO];
[deadTimeLineItem setTarget:self];
TaskDeadTimeLineView *deadTimeLineView = [[TaskDeadTimeLineView alloc] initWithFrame:NSMakeRect(0, 0, 200, 40)];
[deadTimeLineItem setView:deadTimeLineView];
[self addItem:deadTimeLineItem];

//Action
- (void)showCalendarAction:(NSMenuItem *)item {
    if (self.menuDelegate && [self.menuDelegate respondsToSelector:@selector(showCalendarViewWith:)]) {
        [self.menuDelegate showCalendarViewWith:item];
    }
}

0 个答案:

没有答案