Instantiate custom NSWindow

  • Well..as you can guess I'm having some problems adapting from C++ to
    Cocoa environment.
    My problem now is I have a window and had created a custom class for
    this window (DataWindow).
    Now in the application controller I have this:
    #include "DataWindow.h"
    so I can instantiate this class.

    But if I write this
    NSWindow *r=[DataWindow new];
    [NSApp beginSheet:r modalForWindow:window modalDelegate:self
    didEndSelector:nil contextInfo:NULL];
    [NSApp runModalForWindow:r];

    all that I obtain is an empty window.
    What I'm doing wrong?

    --
    http://zon7blog.blogspot.com/
    And again we fall.
  • On 24 Sep 2007, at 1:10 PM, Jere Gmail wrote:

    > My problem now is I have a window and had created a custom class for
    > this window (DataWindow).

    This is surprising. NSWindow is almost never subclassed, at least for
    the apparently-routine sort of display that the name DataWindow implies.

    > Now in the application controller I have this:
    > #include "DataWindow.h"
    > so I can instantiate this class.
    >
    > But if I write this
    > NSWindow *r=[DataWindow new];
    > [NSApp beginSheet:r modalForWindow:window modalDelegate:self
    > didEndSelector:nil contextInfo:NULL];
    > [NSApp runModalForWindow:r];
    >
    > all that I obtain is an empty window.
    > What I'm doing wrong?

    Impossible to tell, without knowing how you implement DataWindow;
    especially how you populate its contentView.

    — F
  • the window is populated in Interface builder. And I have an outlet to
    that window, but I wanna be able to display the window twice.

    On 9/24/07, Fritz Anderson <fritza...> wrote:
    >
    > On 24 Sep 2007, at 1:10 PM, Jere Gmail wrote:
    >
    >> My problem now is I have a window and had created a custom class for
    >> this window (DataWindow).
    >
    > This is surprising. NSWindow is almost never subclassed, at least for
    > the apparently-routine sort of display that the name DataWindow implies.
    >
    >> Now in the application controller I have this:
    >> #include "DataWindow.h"
    >> so I can instantiate this class.
    >>
    >> But if I write this
    >> NSWindow *r=[DataWindow new];
    >> [NSApp beginSheet:r modalForWindow:window modalDelegate:self
    >> didEndSelector:nil contextInfo:NULL];
    >> [NSApp runModalForWindow:r];
    >>
    >> all that I obtain is an empty window.
    >> What I'm doing wrong?
    >
    > Impossible to tell, without knowing how you implement DataWindow;
    > especially how you populate its contentView.
    >
    > — F
    >
    >

    --
    http://zon7blog.blogspot.com/
    And again we fall.
  • On Sep 24, 2007, at 11:41 AM, Jere Gmail wrote:

    > the window is populated in Interface builder. And I have an outlet to
    > that window, but I wanna be able to display the window twice.
    >
    You're almost certainly approaching this the "wrong" way.
    Cocoa has different design patterns than those you're probably used to
    -- as Fritz indicated, for example it's unusual to subclass NSWindow
    unless you want to create a custom look for it.

    I would suggest reviewing <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals
    /index.html
    >.

    If you actually want to display two windows, then consider factoring
    the UI into a separate nib file -- see <> (from the reference above) and <<A href="http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_1.html">http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/
    CocoaNibs/chapter_3_section_1.html
    >.

    mmalc
  • Thanks, I'll read it.
    But, what's the meaning of "Release when closed" in Interface Builder
    if I can not create another instance of this window?

    By the way, is there any function that is called when the window is
    displayed? When I call the runmodal I want some fields on this window
    to update with some global variables but as far as I have searched
    have only found awakefromnib but not onFocus or something like this.

    On 9/24/07, mmalc crawford <mmalc_lists...> wrote:
    >
    > On Sep 24, 2007, at 11:41 AM, Jere Gmail wrote:
    >
    >> the window is populated in Interface builder. And I have an outlet to
    >> that window, but I wanna be able to display the window twice.
    >>
    > You're almost certainly approaching this the "wrong" way.
    > Cocoa has different design patterns than those you're probably used to
    > -- as Fritz indicated, for example it's unusual to subclass NSWindow
    > unless you want to create a custom look for it.
    >
    > I would suggest reviewing <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals
    /index.html
    >  >.
    >
    > If you actually want to display two windows, then consider factoring
    > the UI into a separate nib file -- see <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals
    /CoreAppArchitecture/chapter_7_section_8.html
    >  > (from the reference above) and <http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/
    CocoaNibs/chapter_3_section_1.html
    >  >.
    >
    > mmalc
    >
    >

    --
    http://zon7blog.blogspot.com/
    And again we fall.
  • On Sep 24, 2007, at 2:24 PM, Jere Gmail wrote:
    > By the way, is there any function that is called when the window is
    > displayed? When I call the runmodal I want some fields on this window
    > to update with some global variables but as far as I have searched
    > have only found awakefromnib but not onFocus or something like this.

    It isn't the job of the window to update that information, but rather
    the controller.  One would normally make a subclass of
    NSWindowController for something like this, and implement
    windowDidLoad (which lets you know that it is ready to be populated
    with appropriate information, so  it will be ready to go when it
    actually is displayed).

    For more obscure needs, you can also set the window's delegate and
    implement "windowWillDisplay:", but in general, you'll want to work
    with the Model-View-Controller architecture rather than fight against
    it by subclassing NSWindow and expecting it to update the
    information.  It may seem odd coming from a non MVC based
    architecture, but it's the right way to work with Cocoa...

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | flame : flame fractals & strange attractors : build,
    mutate, evolve, animate
previous month september 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