2012-04-08 1 views

Répondre

12

Je l'utilise dans un viewcontroller

//initWithNibName 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:self.view.window]; 

- (void)windowWillClose:(NSNotification *)notification 
    { 
     NSWindow *win = [notification object]; 
     //... 
    } 
+3

ou vous pouvez définir votre 'NSWindowController' comme' 'NSWindowsDelegate' et faire [self.window setDelegate: auto]' et ajoutez '- (void) windowWillClose: (NSNotification *) notification' dans votre classe de contrôleur. –

1

Vous pouvez déclarer votre classe personnalisée pour se conformer au protocole NSWindowDelegate.

Définir une instance de votre classe personnalisée pour être le délégué de la fenêtre

Ensuite, utilisez l'une de ces méthodes (probablement le windowWillClose: un) de faire quelque chose avant que la fenêtre se ferme.

- (BOOL)windowShouldClose:(id)sender 
- (void)windowWillClose:(NSNotification *)notification 
Questions connexes