Window OnVisible

  • What method should I override, or to what notification should I
    subscribe to know when a window gets shown on the screen (goes from
    hidden to visible). In other words the opposite of
    NSWindowWillCloseNotification
    -Vance
  • On Oct 5, 2007, at 6:44 PM, vance wrote:

    > What method should I override, or to what notification should I
    > subscribe to know when a window gets shown on the screen (goes from
    > hidden to visible). In other words the opposite of
    > NSWindowWillCloseNotification

    Your best bet is probably NSWindowDidExposeNotification, but that
    notification may be called for other reasons as well.

    Scott
  • Thanks, I am trying to do some memory intensive processing when the
    window shows up and then release all the memory when the window
    disappears (is closed)

    Does that mean I have to keep track of the window state myself? (for
    example, before makeKeyAndOrderFront is called, I should set a
    variable bVisible = YES and set bVisible = NO on the
    NSWindowDidExposeNotification notification handler, and only run my
    code when there is a transition from NO to YES inside the
    NSWindowDidExposeNotification handler)

    Also, is there an easy way for Interface Builder NOT to create an
    instance of this NSWindow class, and let me create the instance and
    set the outlet myself, on demand, when the window is needed. (that
    way I could put this code inside init)

    I am new to cocoa and mac development so I am not very sure of the
    best way to implement this.

    -Vance

    On Oct 5, 2007, at 6:50 PM, Scott Thompson wrote:

    >
    > On Oct 5, 2007, at 6:44 PM, vance wrote:
    >
    >> What method should I override, or to what notification should I
    >> subscribe to know when a window gets shown on the screen (goes
    >> from hidden to visible). In other words the opposite of
    >> NSWindowWillCloseNotification
    >
    > Your best bet is probably NSWindowDidExposeNotification, but that
    > notification may be called for other reasons as well.
    >
    > Scott
    >
  • Vance,

    I think you can use some combination of -[NSWindow isVisible], -
    [NSWindow isKeyWindow] and -[NSApplication isActive] to determine if
    you are the foremost window, rather than add your own variable.

    To control when the window is opened, in IB uncheck the "Visible at
    launch time" option for the Window in the inspector.  Set a custom
    class for the File's Owner object in IB and then use :

    BOOL loadedNib = [NSBundle loadNibNamed:@"<name of your nib, without
    extension" owner:<instance of your custom class, set as File's Owner
    in IB>];

    or -[NSWindow makeKeyAndOrderFront] as appropriate for your needs.

    You may also want to use the "Release when closed" option in IB,
    which will release the memory used by the Window and call the dealloc
    method if you have a custom NSWindow object.  Note that this won't
    release the window controller, so may not be helpful to you.

    Sanjay

    > vance wrote
    >
    > Thanks, I am trying to do some memory intensive processing when the
    > window shows up and then release all the memory when the window
    > disappears (is closed)
    >
    > Does that mean I have to keep track of the window state myself?
    > (for example, before makeKeyAndOrderFront is called, I should set a
    > variable bVisible = YES and set bVisible = NO on the
    > NSWindowDidExposeNotification notification handler, and only run my
    > code when there is a transition from NO to YES inside the
    > NSWindowDidExposeNotification handler)
    >
    > Also, is there an easy way for Interface Builder NOT to create an
    > instance of this NSWindow class, and let me create the instance and
    > set the outlet myself, on demand, when the window is needed. (that
    > way I could put this code inside init)
    >
    > I am new to cocoa and mac development so I am not very sure of the
    > best way to implement this.
    >
    > -Vance
    >
    >> On Oct 5, 2007, at 6:50 PM, Scott Thompson wrote:
    >>
    >>
    >>> On Oct 5, 2007, at 6:44 PM, vance wrote:
    >>>
    >>> What method should I override, or to what notification should I
    >>> subscribe to know when a window gets shown on the screen (goes
    >>> from hidden to visible). In other words the opposite of
    >>> NSWindowWillCloseNotification
    >>
    >> Your best bet is probably NSWindowDidExposeNotification, but that
    >> notification may be called for other reasons as well.
    >>
    >> Scott
    >>
    >
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today