views:

65

answers:

1

Hi,

I am trying to update another windows when the one becomes visible. So I found the NSWindowDidExposeNotification and tried to work with it, so I wrote in my awakeFromNib:

// MyClass.m
- (void)awakeFromNib {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self
           selector:@selector(mentionsWindowDidExpose:)
               name:NSWindowDidExposeNotification
             object:nil];
}

and implemented the method

// MyClass.h
- (void)mentionsWindowDidExpose:(id)sender;

// MyClass.m
- (void)mentionsWindowDidExpose:(id)sender {
    NSLog(@"test");
}

But it never gets called which is odd. What do I do wrong here?

+1  A: 
e.James
Ah yeah, that works nice, thanks I'll use that. But then I think I don't understand what NSWindowDidExposeNotification is fof.
Jeena
My response was too long for a comment, so I posted it in my answer. I hope that's enough information to get you started! `:)`
e.James
Thanks, just one more question ;). What do they mean my a "nonretained NSWindow"? I't isn't where the retain count is just 0 or is it?
Jeena
I added a link to my answer. Nonretained windows are defined as windows that do not have an off-screen buffer, so they must draw directly to the screen at all times. I suppose that explains the importance of the `WindowDidExpose` notification: it is used to indicate that a portion of the nonretained window has been uncovered (for instance if you moved another window on top of it, and then moved it away again). A buffered window would simply redraw the contents of the buffer to fill in the erased area, but the nonretained window has no buffer, so it *must* redraw it manually.
e.James
Cool, now I understand, thank you very much :-)
Jeena
No worries. Good luck with the coding! `:)`
e.James