Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Object not receiving awakeFromNib

Object not receiving awakeFromNib
Thread Tools
DayLateDon
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 17, 2005, 05:46 AM
 
Hello ...

One of my object classes (subclass of NSObject, and instantiated in Interface Builder) is no longer receiving "awakeFromNib" messages.

I write "no longer" because, in a previously-saved version of my project, awakeFromNib came through properly.

Suspecting nib corruption, I've deleted and replaced the IB instance, created extra instances, removed and replaced the class reference in IB. I've even created a new project and dropped the class header into the nib, instantiating from there; still no awakeFromNib, although the method is listed in the header.

Suggestions?
     
asdasd
Forum Regular
Join Date: Apr 2003
Location: Santa Clara
Status: Offline
Reply With Quote
Apr 19, 2005, 11:20 PM
 
misspelling?

all objects should get this notification.....
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 19, 2005, 11:47 PM
 
Is the object being instantiated at all? (does it ever get an "init" message?)
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Apr 20, 2005, 06:16 PM
 
I agree with checking init...override init and throw in an NSBeep() or something like that...
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 20, 2005, 06:51 PM
 
Originally Posted by techtrucker
I agree with checking init...override init and throw in an NSBeep() or something like that...
Or a simple NSLog call.

Let us know the results!
     
asdasd
Forum Regular
Join Date: Apr 2003
Location: Santa Clara
Status: Offline
Reply With Quote
Apr 20, 2005, 08:19 PM
 
Gdb banned these days?
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Apr 21, 2005, 04:54 PM
 
I'm inherently lazy...type NSBeep(); , hit cmd-s cmd-r and wait for the beep!
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 21, 2005, 06:54 PM
 
Originally Posted by techtrucker
I'm inherently lazy...type NSBeep(); , hit cmd-s cmd-r and wait for the beep!
I'm also lazy... I usually manage to do a copy/paste... saves all that tiresome typing.

I sure miss "Macro Maker" from the System 6 days. It was the perfect tool for lazy coders.
     
asdasd
Forum Regular
Join Date: Apr 2003
Location: Santa Clara
Status: Offline
Reply With Quote
Apr 21, 2005, 07:00 PM
 
All very well but I imagine typing NSBeep is slower than setting a breakpoint.
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Apr 22, 2005, 06:25 PM
 
Oh, but cmd-Y is more of a finger stretch than cmd-R...
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 24, 2005, 09:01 AM
 
Hello ...

Sorry to have ducked out of my own thread.

Anyway, I've NSLogged my brains out trying to locate the problem. My object is receiving "init" just fine, gets delegate messages from the App and other objects. It performs perfectly normally so far as I can tell, but it just isn't calling "awakeFromNib", which in my code is exactly this:

Code:
- (void)awakeFromNib { NSLog(@"awake!!!!!!!!!!!!"); }
I've re-typed the method, I've copied versions in from objects that are awaking properly, I've moved the method to other places in the code. There's no misspelling and no accidental commenting-out.

Hmmmm ... This is odd. If I make this call somewhere:

Code:
NSLog(@"superclass:%@ respondsToAwakeFromNib:%@", [[self superclass] description], [[self superclass] instancesRespondToSelector:@selector(awakeFromNib)] ? @"YES" : @"NO");
I get this in the Run Log:

Code:
superclass:NSObject respondsToAwakeFromNib:NO
Unless I've made an error with *that* code (adapted from a listing in the NSNibAwaking protocol documentation), it seems that my object doesn't think NSObject gets awakeFromNib calls! I suppose that's consistent with my problem, but it deepens the mystery. (If I use "self" instead of "[self superclass]" I get "selectorNotRecognized" errors with "instancesRespondToSelector".) Cocoa headers are imported.


Here's something else ... I created a category ("AwakingCategory") for NSObject that does nothing but call NSLog(@"awake:%@", [[self class] description]) in an awakeFromNib method. As one might expect, the Run Log explodes with "awake" notices ("awake:NSView", "awake:NSMenuItem", "awake:MyCustomClass1", "awake:MyCustomClass2", ...), but "awake:MyProblematicObject" is not among them, even if I remove the "awakeFromNib" method from the MyProblematicObject class implementation itself to ensure no conflicts with the category method.

Yet ... MyProblematicObject is a subclass of NSObject! (Isn't just about everything?) The "respondsTo..." code snippet above recognizes NSObject as the superclass of MyProblematicObject.


And here's another wrinkle: With AwakingCategory in play, that "respondsToAwakeFromNib" logger above suddenly reports "YES". But if I call "[self awakeFromNib]", I don't get action from either the MyProblematicClass method or the category method.


What could be going on?

     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 24, 2005, 12:09 PM
 
Originally Posted by DayLateDon
Unless I've made an error with *that* code (adapted from a listing in the NSNibAwaking protocol documentation), it seems that my object doesn't think NSObject gets awakeFromNib calls! I suppose that's consistent with my problem, but it deepens the mystery. (If I use "self" instead of "[self superclass]" I get "selectorNotRecognized" errors with "instancesRespondToSelector".) Cocoa headers are imported.
NSObject does not respond to awakeFromNib. You implement it in your own class. Use [self class] instead of [self superclass], since instancesRespondToSelector is a class method not an instance method (or use the corresponding respondsToSelector instance method).

Are you sure your problematic object is really being instantiated from your nib? Are you sure the object in your nib has the correct "Custom class" property?
     
asdasd
Forum Regular
Join Date: Apr 2003
Location: Santa Clara
Status: Offline
Reply With Quote
Apr 24, 2005, 12:13 PM
 
You may want to check the backtrace at initialization time to see if you are being instantiated by Interface builder, as you think, or by your own code after the awakeFromNib notification has already fired.
     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 24, 2005, 12:31 PM
 
Originally Posted by Angus_D
Use [self class] instead of [self superclass], since instancesRespondToSelector is a class method not an instance method (or use the corresponding respondsToSelector instance method).
Ah. Of course. (I'd been thinking "super" where I saw "superclass".) Well, that explains the "deepened mystery" away as my error.

On the other hand, using "[self class]" in the check for "instancesRespondTo...", I'm told that MyProblematicClass *does* respond to awakeFromNib (with or without AwakerCategory in play). Yet ... it doesn't respond.

Originally Posted by Angus_D
Are you sure your problematic object is really being instantiated from your nib?
Unless I misunderstand the question, the object is indeed instantiated. Its blue box is sitting right there in the Instances pane. Moreover, it receives and reacts to messages from objects connected to it, and it sends messages successfully to its connections. Except for this awakeFromNib thing, it behaves totally normally.

Originally Posted by Angus_D
Are you sure the object in your nib has the correct "Custom class" property?
The Custom Class is set. (I had to double-check that one, because I'd deleted and rebuilt the instance a time or two.)

     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 24, 2005, 12:33 PM
 
Originally Posted by asdasd
You may want to check the backtrace at initialization time to see if you are being instantiated by Interface builder, as you think, or by your own code after the awakeFromNib notification has already fired.
Okay, now that suggestion's a little beyond me.

Where can I find out how to do this backtrace stuff?


Edit to add: There's only one instance of this object in my app. (It's my main controller!) It's only created in IB, not dynamically in code.
     
asdasd
Forum Regular
Join Date: Apr 2003
Location: Santa Clara
Status: Offline
Reply With Quote
Apr 24, 2005, 12:59 PM
 
"Edit to add: There's only one instance of this object in my app. (It's my main controller!) It's only created in IB, not dynamically in code."
OK. Then the problem is not what I suggested. To get the backtrace you would run in the debugger, set a breakpoint, and when it stops you will see the backtrace ( the stack of calls which preceded the call into your function).

Generally in the Debugger window in xCode this stack is shown in reverse order in a tableview in the top left of the window . GDB is important for finding out these kind of problems.
( Last edited by asdasd; Apr 24, 2005 at 01:01 PM. Reason: spelling correction)
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 24, 2005, 01:19 PM
 
Can you create a minimal test case one of us could look at? There's obviously something wrong, but it's hard to just randomly guess what it is.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 24, 2005, 01:45 PM
 
Originally Posted by Chuckit
Can you create a minimal test case one of us could look at? There's obviously something wrong, but it's hard to just randomly guess what it is.
Well, I've just stripped virtually all of the code out of my various objects.

MyProblematicObject now responds to awakeFromNib.

So, somehow I've managed to code away nib awaking. I guess I don't know my own strength!


Now, of course, I need to do less drastic and more systematic code purging to see where things change. I'm going to need to take a break before I do that.


Thanks for continuing insights ...
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Apr 24, 2005, 03:46 PM
 
Do keep us posted, this one has me curious...good luck!
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
May 1, 2005, 02:12 AM
 
Originally Posted by techtrucker
Do keep us posted, this one has me curious...good luck!
I don't need luck, I just need a better memory.

I'd created a category for MyProblematicObject (so that it could handle toolbar delegate duties). In the hazy past of this project, I added awakeFromNib to the category, and that was catching all my calls.




Thanks for the input.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:11 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,