Re: awakeFromNib being called twice?
Re: awakeFromNib being called twice?
- Subject: Re: awakeFromNib being called twice?
- From: Phill Kelley <email@hidden>
- Date: Tue, 27 Jul 2004 10:43:57 +1000
At 18:20 -0700 25/07/2004, Jesse Thompson wrote:
>
'm writing an OpenGL program in C++, but am using Objective-C++ /
>
Cocoa for the GUI front-end. For some reason awakeFromNib,
>
initWithFrame:, and initGL are all being called twice. awakeFromNib is
>
responsible for calling a C++ function within one of my C++ back-end
>
classes which creates a list of objects.... Now does this mean that I
>
have two instances of this list? Is it normal for these functions to
>
be executed twice? If not, any suggestions on how to fix it? I've done
>
a little bit of searching and it seems to be a bi-product of
>
NSDocument based programs, but this is just subclassed OpenGLView. So
>
the header of my one and only Objective-C++ class is:
>
@interface MyOpenGLView : NSOpenGLView
>
Appreciate any help you can give me.
Two things I'd suggest. Firstly, I normally include this define in the
prefix header for all my projects (it's all on one line):
#define MARK(number) NSLog(@"%@(0x%X) %@.%d",[self
className],self,NSStringFromSelector(_cmd),number);
When I want to know whether a particular piece of code is being exercised,
I just stuff "MARK(1)" at a convenient point. You'll see that it logs the
name of the class and the memory address of the instance, as well as the
method MARK was called in. The number is just a differentiator in case I
have more than one mark in a method.
If you stick MARK calls into your initWithFrame and awakeFromNib calls and
the init/awake pairs have different memory addresses, then it will show
that you've created two instances of your object. If so, a common culprit
is that you have both "File's Owner" and a separate instantiation in your
nib. Check out the class of File's Owner. If you also have another icon in
the nib which has the same class then the chances are you don't need the
second one. Also consider the situation where a view inside a window has a
class "x" and you've explicitly instantiated an "x". Again, you probably
don't need both.
On the other hand, if all the messages coming from MARK statements have the
same address then it's probably something you're doing in code. I came
across a strange situation where I was calling setFrameAutosaveName in an
init method and it was calling awakeFromNib prematurely. It might be
something like that. Either add additional MARK calls or step your code to
work out what API calls might have unexpected side-effects.
Regards, Phill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.