Having trouble just displaying a window

  • I'm not sure where I originally found this example, but I can't seem
    to make it work. I use the following code to implement an inspector
    NSPanel that hides and shows each time the menu item is chosen.

    @implementation STXAppDelegate

    - (IBAction)
    showChartInspector: (id) inSender
    {
    if (mChartInspectorController == NULL)
    {
      mChartInspectorController = [[NSWindowController alloc]
    initWithWindowNibName: @"ChartInspector"];

      [mChartInspectorController setWindowFrameAutosaveName:
    @"ChartInspector"];
    }

    [mChartInspectorController showOrHideWindow];
    }

    .
    .
    .

    I can put a breakpoint there, and trace it into:

    - (void)
    showOrHideWindow
    {
    if ([self isWindowShown])
    {
      [[self window] orderOut: self];    // Hide the window
    }
    else
    {
      [self showWindow: self];    // Show the window
    }
    }

    it executes [self showWindow: self], but no window appears.

    I'm new to Cocoa, but this seems straightforward. What might I be
    missing?

    TIA,
    Rick
  • On Nov 14, 2007, at 11:11 PM, Hal Mueller wrote:

    > What class have you written -showOrHideWindow on?  Is
    > mChartInspectorController an instance of some subclass of
    > NSWindowController?  What is the value of window when -
    > showOrHideWindow is called ( NSLog(@"window: %@", window); )?

    Oh! the window is null:

    2007-11-14 23:36:37.599 SatTrackX[14201:813] window: (null)

    Sorry, I don't yet know enough about NSWindowController to know why it
    doesn't show. I have a .xib file named ChartInspector.xib, and the
    window inside that is named "ChartInspector". Nice of Cocoa to let me
    know why it's not loading...

    showOrHideWindow is added to NSWindowController in the file before the
    inspector window's controller is allocated:

    @interface NSWindowController(STXConvenience)
    - (BOOL) isWindowShown;
    - (void) showOrHideWindow;
    @end

    @implementation NSWindowController(STXConvenience)

    - (BOOL)
    isWindowShown
    {
    return [[self window] isVisible];
    }

    - (void)
    showOrHideWindow
    {
    if ([self isWindowShown])
    {
      [[self window] orderOut: self];    // Hide the window
    }
    else
    {
      [self showWindow: self];    // Show the window
    }
    }

    @end
  • On Nov 14, 2007, at 11:57 PM, Hal Mueller wrote:

    > I took a look at the NSWindowController documentation.  I believe
    > that "window" won't exist until you send the NSWindowController
    > instance a -window message.

    Well, isn't that what I'm doing when I call [self window]?

    > I'm also thinking that you really want to be sending the window a -
    > close, not -orderOut.

    That is a nicer-sounding name, but the example I started from (that I
    can't find now) used -orderOut.

    --
    Rick
  • First off, why are you using your own method for -isWindowShown?
    NSWindow (which NSPanel inherits from) provides several methods to
    make the window (or panel) visible.  See http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Cla
    sses/NSWindow_Class/Reference/Reference.html

      .

    -Sam

    On Nov 14, 2007, at 10:33 PM, Rick Mann wrote:

    > I'm not sure where I originally found this example, but I can't seem
    > to make it work. I use the following code to implement an inspector
    > NSPanel that hides and shows each time the menu item is chosen.
    >
    >
    >
    > @implementation STXAppDelegate
    >
    >
    > - (IBAction)
    > showChartInspector: (id) inSender
    > {
    > if (mChartInspectorController == NULL)
    > {
    > mChartInspectorController = [[NSWindowController alloc]
    > initWithWindowNibName: @"ChartInspector"];
    >
    > [mChartInspectorController setWindowFrameAutosaveName:
    > @"ChartInspector"];
    > }
    >
    > [mChartInspectorController showOrHideWindow];
    > }
    >
    > .
    > .
    > .
    >
    >
    > I can put a breakpoint there, and trace it into:
    >
    > - (void)
    > showOrHideWindow
    > {
    > if ([self isWindowShown])
    > {
    > [[self window] orderOut: self];                //    Hide the window
    > }
    > else
    > {
    > [self showWindow: self];                    //    Show the window
    > }
    > }
    >
    >
    > it executes [self showWindow: self], but no window appears.
    >
    > I'm new to Cocoa, but this seems straightforward. What might I be
    > missing?
    >
    > TIA,
    > Rick
  • On Nov 15, 2007, at 3:05 AM, Rick Mann wrote:

    >
    > On Nov 14, 2007, at 11:11 PM, Hal Mueller wrote:
    >
    >> What class have you written -showOrHideWindow on?  Is
    >> mChartInspectorController an instance of some subclass of
    >> NSWindowController?  What is the value of window when -
    >> showOrHideWindow is called ( NSLog(@"window: %@", window); )?
    >
    > Oh! the window is null:
    >
    > 2007-11-14 23:36:37.599 SatTrackX[14201:813] window: (null)

    In IB, change the "Window's Owner" class to NSWindowController. Then
    connect the owner's "window" outlet to the window.

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
  • On Nov 15, 2007, at 12:41 AM, Sherm Pendley wrote:

    > In IB, change the "Window's Owner" class to NSWindowController. Then
    > connect the owner's "window" outlet to the window.

    I take it you mean "File's Owner", not "Window's Owner," right? At
    least, that's what I have in my file. Anyway, doing that fixed it.
    Thank you very much!

    --
    Rick
  • On Nov 15, 2007, at 4:44 AM, Rick Mann wrote:

    > On Nov 15, 2007, at 12:41 AM, Sherm Pendley wrote:
    >
    >> In IB, change the "Window's Owner" class to NSWindowController.
    >> Then connect the owner's "window" outlet to the window.
    >
    > I take it you mean "File's Owner", not "Window's Owner," right?

    Right, sorry about that. I posted before coffee. :-(

    > At least, that's what I have in my file. Anyway, doing that fixed it.

    I'm glad my under-caffeinated response wasn't an obstacle. :-)

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
  • This is the same issue I posted about a couple of weeks ago.  Like
    myself, he just followed what was in the Sketch sample code and found out it
    didn't work when using a .xib instead of a the original .nib with the
    earlier IB.  Something gets lost in the translation.  Using the window
    controller for the file's owner instead of the Application fixes it.  That's
    also why the newer Sketch .xib includes an explicit controller object solely
    for the purpose of getting a direct connection to the Application.

    > On Nov 15, 2007, at 4:44 AM, Rick Mann wrote:
    >
    >> On Nov 15, 2007, at 12:41 AM, Sherm Pendley wrote:
    >>
    >>> In IB, change the "Window's Owner" class to NSWindowController.
    >>> Then connect the owner's "window" outlet to the window.
    >>
    >> I take it you mean "File's Owner", not "Window's Owner," right?
    >
    > Right, sorry about that. I posted before coffee. :-(
    >
    >> At least, that's what I have in my file. Anyway, doing that fixed it.
    >
    > I'm glad my under-caffeinated response wasn't an obstacle. :-)
    >
    > sherm--
    >
    > Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    > Cocoa programming in Perl: http://camelbones.sourceforge.net
    >
    >
  • On Nov 15, 2007, at 8:52 AM, Gordon Apple wrote:

    > This is the same issue I posted about a couple of weeks ago.  Like
    > myself, he just followed what was in the Sketch sample code and
    > found out it
    > didn't work when using a .xib instead of a the original .nib with the
    > earlier IB.  Something gets lost in the translation.  Using the window
    > controller for the file's owner instead of the Application fixes
    > it.  That's
    > also why the newer Sketch .xib includes an explicit controller
    > object solely
    > for the purpose of getting a direct connection to the Application.

    Oh, I guess I should clarify. The File's Owner had already been set to
    NSWindowController. What I had failed to do was to set it's window
    outlet to point to my window object in IB. That was my missing link
    (literally).

    --
    Rick
previous month november 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    
Go to today