Professional Web Applications Themes

initialize between initWithCoder and awakeFromNib - Mac Programming

Hello again. I seem to be having a problem understanding the sequence of events that NSDoent programs go through for initialization. Here is my setup, followed by my question. I have an NSDoent 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: MyDoent->init End: MyDoent->init Begin: MyOpenGLVIew->initWithCoder End: MyOpenGLVIew->initWithCoder Begin: MyOpenGLVIew->awakeFromNib End: MyOpenGLVIew->awakeFromNib Begin: MyOpenGLVIew->drawRect End: MyOpenGLVIew->drawRect Begin: MyDoent->windowControllerDibLoadNib End: MyDoent->windowControllerDibLoadNib Ideally, I would like to be able to call ...

  1. #1

    Default initialize between initWithCoder and awakeFromNib

    Hello again.

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

    I have an NSDoent 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: MyDoent->init
    End: MyDoent->init
    Begin: MyOpenGLVIew->initWithCoder
    End: MyOpenGLVIew->initWithCoder
    Begin: MyOpenGLVIew->awakeFromNib
    End: MyOpenGLVIew->awakeFromNib
    Begin: MyOpenGLVIew->drawRect
    End: MyOpenGLVIew->drawRect
    Begin: MyDoent->windowControllerDibLoadNib
    End: MyDoent->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 MyDoent to do that. I tried passing the parameter
    during MyDoent->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. #2

    Default Re: initialize between initWithCoder and awakeFromNib

    In article <fa39fc69.0308220047.5facb481posting.google.com >, matt
    <matthew.romainejp.sony.com> wrote:
    > Hello again.
    >
    > I seem to be having a problem understanding the sequence of events
    > that NSDoent programs go through for initialization. Here is my
    > setup, followed by my question.
    >
    > I have an NSDoent 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: MyDoent->init
    > End: MyDoent->init
    > Begin: MyOpenGLVIew->initWithCoder
    > End: MyOpenGLVIew->initWithCoder
    > Begin: MyOpenGLVIew->awakeFromNib
    > End: MyOpenGLVIew->awakeFromNib
    > Begin: MyOpenGLVIew->drawRect
    > End: MyOpenGLVIew->drawRect
    > Begin: MyDoent->windowControllerDibLoadNib
    > End: MyDoent->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 MyDoent to do that. I tried passing the parameter
    > during MyDoent->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

  3. #3

    Default Re: initialize between initWithCoder and awakeFromNib

    matt <matthew.romainejp.sony.com> wrote:
    > Hello again.
    >
    > I seem to be having a problem understanding the sequence of events
    > that NSDoent programs go through for initialization. Here is my
    > setup, followed by my question.
    >
    > I have an NSDoent 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 MyDoent to do that. I tried passing the parameter
    > during MyDoent->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 doent
    class (assuming the doent 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 doent subclass (or some other
    appropriate object) in IB. Have glview->awakeFromNib call a method like:

    importantInitValue = [initDelegate glviewWantsSomeInformation];
    Paul Mitchum Guest

  4. #4

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

    matt <matthew.romainejp.sony.com> wrote:
    > [email]usenetmile23.com[/email] (Paul Mitchum) wrote in message
    > news:<1g03b6h.14rswyd1e3839sN%usenetmile23.com>.. .
    > > matt <matthew.romainejp.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 doent
    > > class (assuming the doent 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 doent 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 doent 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
    > NSDoent-based programs with the NSDoent 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 NSDoent 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 doent class to hold its hand.
    Also, changing the NSDoent subclass would have less effect on it.
    Strong cohesion, loose coupling, etc. :-)
    > On a different topic, could someone clarify the difference between
    > NSDoent'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 doent's
    > window.") seems to suggest it's called after a window representing
    > just the NSDoent 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
    doent 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 doent, 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

Similar Threads

  1. Get pdf filename during initialize:
    By cstham@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 9
    Last Post: July 21st, 06:50 AM
  2. CT CS3 wont initialize
    By heimskr in forum Macromedia Contribute General Discussion
    Replies: 3
    Last Post: October 20th, 07:24 AM
  3. Organizer will not initialize
    By Jeremiah_Savage@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: May 9th, 10:01 PM
  4. Help with Initialize
    By rottmanja in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: December 14th, 10:20 PM
  5. initialize COM within a web service
    By POnfri in forum ASP.NET Web Services
    Replies: 2
    Last Post: March 10th, 10:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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