如何以编程方式关闭NSPopover [英] How to Close NSPopover programmatically
问题描述
我想知道如何以编程方式关闭NSPopover,而不是通过触摸外部来关闭NSPopover,因为我想将其分配给某个动作(例如KeyDown Enter Key或其他快捷键)
I want to know how to close NSPopover programmatically, not by touching outside, because I want to assign it to an action (such as KeyDown Enter Key or other shortcut)
因为我使用快捷方式打开了NSPopover,所以按另一个命令来关闭NSPopover会更合逻辑
because I open my NSPopover with a shortcut, it would be more logical to close by pressing another command
要分享我的代码:
EdiciondeCuentasWC.h(NSWindowController),我从这里调用我的NSPopover
EdiciondeCuentasWC.h (NSWindowController) from where I call my NSPopover
#import "EdicionDeCuentasWC.h"
#import "CambiarTipoCuentaVC.h"
@interface EdicionDeCuentasWC ()<NSPopoverDelegate>{
CambiarTipoCuentaVC *cambiarTipoCuentaVC;
}
@property (strong) IBOutlet NSPopover *popoverClasifCuentas;
@end
@implementation EdicionDeCuentasWC
-(void)mostrarPopupCambiarTipoCta{
cambiarTipoCuentaVC = (CambiarTipoCuentaVC *) _popoverCambiarTipoCuentas.contentViewController;
cambiarTipoCuentaVC.nombre_tipo_cta = arrayActivos[renglonSeleccionado][@"nombre_tipo_cta"];
cambiarTipoCuentaVC.prioridad_cta = arrayActivos[renglonSeleccionado][@"prioridad_cta"];
NSTableCellView *cellView = [_activoTableView viewAtColumn:0
row:renglonSeleccionado
makeIfNecessary:NO];
[_popoverClasifCuentas setDelegate:self];
[cambiarTipoCuentaVC inicializarDatos];
[_popoverCambiarTipoCuentas showRelativeToRect:[cellView bounds] ofView:cellView preferredEdge:NSMaxXEdge];
}
#pragma mark NSPopoverDelegate
-(void)popoverWillClose:(NSNotification *)notification{
NSPopover *popover = (NSPopover *)[notification object]; //there I have the code for managing all the returning parameters...
}
@end
我的NSPopover的代码在NSViewController(CambiarTipoCuentaVC)里面,但是在里面我既没有[self close]也没有[self performClose]来使它通过按钮或快捷方式关闭,任何帮助使其工作的帮助我非常感谢...
And the code of my NSPopover is inside of a NSViewController (CambiarTipoCuentaVC) but inside there I there's neither [self close] nor [self performClose] for making it close from a button, or shortcut, any help to make it work I'd appreciate...
推荐答案
您甚至还看过NSPopover
文档吗?它具有-close
方法,并且出于稍微不同的目的,具有-performClose:
方法.
Have you even looked as far as the NSPopover
documentation? It has a -close
method and, for a slightly different purpose, -performClose:
method.
这篇关于如何以编程方式关闭NSPopover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!