Ask a Question related to Mac Programming, Design and Development.
-
matt #1
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
-
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... -
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... -
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... -
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... -
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 -
Steve Ketcham #2
Re: initialize between initWithCoder and awakeFromNib
In article <fa39fc69.0308220047.5facb481@posting.google.com >, matt
<matthew.romaine@jp.sony.com> wrote:
Matt,> 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?
>
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
-
Paul Mitchum #3
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:awakeFromNib gets called after all the nib objects have been created and> 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?
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
-
Paul Mitchum #4
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:Well, Matt (the other one) says he needs to move some information>> >> > > 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.
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.
Well, that's not a bad way to go about it. But if you think about it:> 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.
The reason NSDocument objects get crammed with delegate methods is
because the Cocoa controls on the window all use the delegate strategy I
suggested.
Well, for me it'd be a question of responsibility. The glview subclass> Hm, I guess it becomes a question of if you want 'smart objects' or
> 'stupid objects'.
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. :-)
I'm pretty sure that windowControllerDidLoadNib is called by any> 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....
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



Reply With Quote

