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)
because I open my NSPopover with a shortcut, it would be more logical to close by pressing another command
going to share my code:
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
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...
In the NSPopover
documentation, there is described a -close
method and, for a slightly different purpose, -performClose:
method.