initialize between initWithCoder and awakeFromNib

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default initialize between initWithCoder and awakeFromNib

    Hello again.

    I seem to be having a problem understanding the sequence of events
    that NSDocument programs go through for initialization. Here is my
    setup, followed by my question.

    I have an NSDocument program that opens up a window holding a subclass
    of NSOpenGLView. I need to pass a parameter to this NSOpenGLView
    subclass *before* it can start calling drawRect. Through NSLog
    outputs, I have determined the function-call sequence to be:

    Begin: MyDocument->init
    End: MyDocument->init
    Begin: MyOpenGLVIew->initWithCoder
    End: MyOpenGLVIew->initWithCoder
    Begin: MyOpenGLVIew->awakeFromNib
    End: MyOpenGLVIew->awakeFromNib
    Begin: MyOpenGLVIew->drawRect
    End: MyOpenGLVIew->drawRect
    Begin: MyDocument->windowControllerDibLoadNib
    End: MyDocument->windowControllerDibLoadNib

    Ideally, I would like to be able to call my own function between the
    MyOpenGLVIew->awakeFromNib and drawRect, but I can't seem to find a
    place within MyDocument to do that. I tried passing the parameter
    during MyDocument->init, but because MyOpenGLView->initWithCoder has
    not been called yet, it doesn't seem to work (although I receive no
    errors; not even a SegV or BusError...).

    How does one pass in parameters for an OpenGLView before the first
    call to drawRect?

    tia
    matt
    matt Guest

  2. Similar Questions and Discussions

    1. CT CS3 wont initialize
      I tried to open up Contribute today and it wouldn't even initialize. The little hour glass shows up for a second then disappears. I'm having the...
    2. Organizer will not initialize
      I too have this problem. I have MySql on my computer for advertising software and I just upgraded my Acrobat to 7, now every time I open it I get the...
    3. Help with Initialize
      I have created a simple test webservice in the form of a cfc. The cfc accepts no arguments and just returns a string, that I want to use to populate...
    4. initialize COM within a web service
      I'm currently trying to use API's in Microsoft Virtual Server 2005. I can initialize COM just fine from anything other then a web service whihc is...
    5. Help with initialize the array in PHP
      uws wrote: what about array_fill ? $cell = array_fill(0,7,array_fill(0,32,-1)); -- --- --- --- --- --- --- --- jack@croatiabiz.com
  3. #2

    Default Re: initialize between initWithCoder and awakeFromNib

    In article <fa39fc69.0308220047.5facb481@posting.google.com >, matt
    <matthew.romaine@jp.sony.com> wrote:
    > Hello again.
    >
    > I seem to be having a problem understanding the sequence of events
    > that NSDocument programs go through for initialization. Here is my
    > setup, followed by my question.
    >
    > I have an NSDocument program that opens up a window holding a subclass
    > of NSOpenGLView. I need to pass a parameter to this NSOpenGLView
    > subclass *before* it can start calling drawRect. Through NSLog
    > outputs, I have determined the function-call sequence to be:
    >
    > Begin: MyDocument->init
    > End: MyDocument->init
    > Begin: MyOpenGLVIew->initWithCoder
    > End: MyOpenGLVIew->initWithCoder
    > Begin: MyOpenGLVIew->awakeFromNib
    > End: MyOpenGLVIew->awakeFromNib
    > Begin: MyOpenGLVIew->drawRect
    > End: MyOpenGLVIew->drawRect
    > Begin: MyDocument->windowControllerDibLoadNib
    > End: MyDocument->windowControllerDibLoadNib
    >
    > Ideally, I would like to be able to call my own function between the
    > MyOpenGLVIew->awakeFromNib and drawRect, but I can't seem to find a
    > place within MyDocument to do that. I tried passing the parameter
    > during MyDocument->init, but because MyOpenGLView->initWithCoder has
    > not been called yet, it doesn't seem to work (although I receive no
    > errors; not even a SegV or BusError...).
    >
    > How does one pass in parameters for an OpenGLView before the first
    > call to drawRect?
    >
    Matt,

    It will be interesting to see if some of the framework gurus have a
    better approach than this, but here's what I'd do:

    In either initWithCoder or awakeFromNib, set a flag to indicate whether
    drawRect should be executed the first time:

    BOOL doTheDrawing = NO;

    then, surround your drawRect code with an if:

    if (doTheDrawing)
    {
    // your drawRect code
    }
    else
    {
    doTheDrawing = YES;
    }

    Then, call your own function, and do what it takes to draw it after
    that.

    Steve
    Steve Ketcham Guest

  4. #3

    Default Re: initialize between initWithCoder and awakeFromNib

    matt <matthew.romaine@jp.sony.com> wrote:
    > Hello again.
    >
    > I seem to be having a problem understanding the sequence of events
    > that NSDocument programs go through for initialization. Here is my
    > setup, followed by my question.
    >
    > I have an NSDocument program that opens up a window holding a subclass
    > of NSOpenGLView. I need to pass a parameter to this NSOpenGLView
    > subclass *before* it can start calling drawRect. Through NSLog
    > outputs, I have determined the function-call sequence to be:
    [..]
    > Ideally, I would like to be able to call my own function between the
    > MyOpenGLVIew->awakeFromNib and drawRect, but I can't seem to find a
    > place within MyDocument to do that. I tried passing the parameter
    > during MyDocument->init, but because MyOpenGLView->initWithCoder has
    > not been called yet, it doesn't seem to work (although I receive no
    > errors; not even a SegV or BusError...).
    >
    > How does one pass in parameters for an OpenGLView before the first
    > call to drawRect?
    awakeFromNib gets called after all the nib objects have been created and
    connected. The problem you're dealing with is exactly what awakeFromNib
    was designed to solve. You could implement awakeFromNib on your document
    class (assuming the document is part of the nib) and have it initialize
    the glview. Alternately, you could have your glview take responsibility
    for itself in its awakeFronNib. The latter is is a better approach, I
    think...

    Add an outlet to your GLView subclass, call it something like
    initDelegate. Connect it to your document subclass (or some other
    appropriate object) in IB. Have glview->awakeFromNib call a method like:

    importantInitValue = [initDelegate glviewWantsSomeInformation];
    Paul Mitchum Guest

  5. #4

    Default Re: initialize between initWithCoder and awakeFromNib (design question)

    matt <matthew.romaine@jp.sony.com> wrote:
    > [email]usenet@mile23.com[/email] (Paul Mitchum) wrote in message
    > news:<1g03b6h.14rswyd1e3839sN%usenet@mile23.com>.. .
    > > matt <matthew.romaine@jp.sony.com> wrote:
    [..]
    > > > How does one pass in parameters for an OpenGLView before the first
    > > > call to drawRect?
    > >
    > > awakeFromNib gets called after all the nib objects have been created and
    > > connected. The problem you're dealing with is exactly what awakeFromNib
    > > was designed to solve. You could implement awakeFromNib on your document
    > > class (assuming the document is part of the nib) and have it initialize
    > > the glview. Alternately, you could have your glview take responsibility
    > > for itself in its awakeFronNib. The latter is is a better approach, I
    > > think...
    > >
    > > Add an outlet to your GLView subclass, call it something like
    > > initDelegate. Connect it to your document subclass (or some other
    > > appropriate object) in IB. Have glview->awakeFromNib call a method like:
    > >
    > > importantInitValue = [initDelegate glviewWantsSomeInformation];
    >
    > Just a tad curious as to why you suggest the latter approach.
    Well, Matt (the other one) says he needs to move some information
    between the document subclass and the glview subclass before display, so
    I presented a couple ways to do it. I shouldn't have said the latter is
    really the best design, especially since I don't know what the rest of
    the program looks like or even does. But it is easier to hook it up in
    IB than to implement awakeFromNib for all your various classes.
    > In terms of design, I have generally been under the impression that
    > objects should know about other objects only when necessary, and that the
    > 'flow' of this knowledge should be top-down. Redundant object knowledge
    > should be kept at a minimum. As such, I have been treating
    > NSDocument-based programs with the NSDocument at the top, knowing all
    > information and data, and sending messages to its 'children' -- in this
    > particular case, the glViews.
    Well, that's not a bad way to go about it. But if you think about it:
    The reason NSDocument objects get crammed with delegate methods is
    because the Cocoa controls on the window all use the delegate strategy I
    suggested.
    > Hm, I guess it becomes a question of if you want 'smart objects' or
    > 'stupid objects'.
    Well, for me it'd be a question of responsibility. The glview subclass
    is more responsible for itself if it has a delegate and maybe a protocol
    it uses to talk to delegate objects. This means I could reuse it
    somewhere else, without a specific document class to hold its hand.
    Also, changing the NSDocument subclass would have less effect on it.
    Strong cohesion, loose coupling, etc. :-)
    > On a different topic, could someone clarify the difference between
    > NSDocument's -awakeFromNib and -windowControllerDidLoadNib? Is the
    > latter called after *all* the windows in the whole program are opened?
    > The comment offered in the template (" // Add any code here that need
    > to be executed once the windowController has loaded the document's
    > window.") seems to suggest it's called after a window representing
    > just the NSDocument is opened....
    I'm pretty sure that windowControllerDidLoadNib is called by any
    windowController that loads a nib file, on the nib file's owner. If your
    document subclass does something like this:

    NSWindowController * auxWC = [[NSWindowController alloc]
    initWithWindowNibName:@"AuxilliaryWindow" owner:self];
    [self addWindowController:auxWC];
    [auxWC showWindow:self];

    .... then windowControllerDidLoadNib will be called on the document, with
    auxWC as the parameter. When this happens depends on the 'deferred'
    checkbox for the window in IB.

    The docs for the NSNibAwaking protocol have a big happy pile of
    information about -awakeFromNib. Check it out.
    Paul Mitchum Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139