Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I track opening and closing event of NSWindow?

Tags:

events

cocoa

I did try – windowDidExpose: but it didn't work. What do I have to try for this?

My window is a utility window.

-- edit for more clarity --

What I want are:

viewWillAppear viewWillDisappear viewDidLoad viewDidUnload

in Cocoa Touch.

like image 722
eonil Avatar asked Aug 18 '10 18:08

eonil


2 Answers

Very old question, but only for documentation purpose:


Track open: In your windows controller override the method:

-(void)showWindow:(id)sender
{
    //add this for track the window close
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(windowWillClose)
                                                 name:NSWindowWillCloseNotification
                                               object:nil];
    [super showWindow:sender];
    //do here what you want...
}

Track close: Implement the method

-(void)windowWillClose
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    //do here what you want...
}
like image 184
Kappe Avatar answered Jan 01 '23 17:01

Kappe


There is windowDidClose:, but that probably only refers to closing; if you're sending your window an orderOut: message, I don't think that counts.

You probably need to either just track it from whatever code you're ordering the window in and out from, or subclass the window's class and override methods like makeKeyAndOrderFront: and orderOut: (whatever you're using, at least) to post custom notifications before calling up to super.

like image 35
Peter Hosey Avatar answered Jan 01 '23 19:01

Peter Hosey