-(voID)mouseDown:(NSEvent *)event{NSPoint pointInVIEw = [self convertPoint:[event locationInWindow] fromVIEw:nil];if (NSPointInRect(pointInVIEw,[self shapeRect]) ){ NSMenu *themenu = [[[NSMenu alloc] initWithTitle:@"default Contextual Menu"] autorelease]; [themenu insertItemWithTitle:@"Circle" action:@selector(circle:) keyEquivalent:@"" atIndex:0]; [themenu insertItemWithTitle:@"Rectangle" action:@selector(rectangle:) keyEquivalent:@"" atIndex:1]; [NSMenu popUpContextMenu:themenu withEvent:event forVIEw:self]; } }
如何给项目打勾?
解决方法 看一下NSUserInterfaceItemValidations
协议.当显示菜单时,它将使用valIDateUserInterfaceItem:方法查询响应者链中的每个响应者,以确定是否应该启用该项. (只要链中的一个响应者返回YES,项目就会启用)这也使您有机会自定义项目.例如: - (BOol)valIDateUserInterfaceItem:(ID <NSValIDatedUserInterfaceItem>)item { if ([item action] == @selector(actionMethodForItemThatShouldBeChecked:)] { // This method is also used for toolbar items,so it's a good IDea to // make sure you're valIDating a menu item here if ([item respondsToSelector:@selector(setState:)]) [item setState:NSOnState]; } return YES;}总结
以上是内存溢出为你收集整理的cocoa – 如何向NSMenuItem添加复选标记全部内容,希望文章能够帮你解决cocoa – 如何向NSMenuItem添加复选标记所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)