Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aliher

macrumors newbie
Original poster
Mar 25, 2009
23
0
UK
Hi,

I'm trying to achieve loading of custom views from nib files.
I have a nib which contains NSView with some controls on it, custom object of class B which was loaded through classes tab and subsequently instantiated. And a filesOwner set to my custom class A. Class A contains a references to NSView and B and I bind this A's outlets in IB to appropriate objects.
Class A has a method to load itself from nib using loadNibNamed:eek:wner: from NSBundle.
The methods returns true which means nib was loaded successfully, but when I try to look at the fields I see that reference to NSView is populated (and I actually use it inside a form to show contents), but the reference to B is always nil.
I've also tried to stick NSObjectController and add another field to A to check if it is a matter of custom class being instantiated, but the result is the same.
Only the NSView instance is created and referenced by fileOwner.
I suggest that B's instance is never created since its init method is never called according to logging and breakpoints.
I think it is quite trivial operation that I'm doing, so I should be missing something in details or conceptually.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
So your nib has 2 top-level objects, a view and a custom object, and the view gets created but the custom object isn't? Did you check for initWithCoder?
 

aliher

macrumors newbie
Original poster
Mar 25, 2009
23
0
UK
Exactly. I tried to add initWithCoder: to the custom object but it doesn't seem to change anything.
I was thinking that loadNibNamed: might be a wrong method to inflate the nib back.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you're on 10.5 I'd suggest using NSViewController as it will make your life easier.

But I'm not sure what else to say. Can you post a screenshot of your nib? Maybe it's configured incorrectly.
 

aliher

macrumors newbie
Original poster
Mar 25, 2009
23
0
UK
Nop I'm on 10.4 so I don't have NSViewController. And I also want to know what is actually happening under the hood. :)
I'll try to post a screenshot and a code snippet when I'm back home though.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Maybe you forgot to set the class of the object and it's still an NSObject or something..
 

aliher

macrumors newbie
Original poster
Mar 25, 2009
23
0
UK
Problem is resolved. It turned out really a schoolboy thing.
I renamed nib file at some point in past and forgot to change the name used to load it.
Xcode kept compiled resource somewhere and it was successfully loaded, but it didn't contained appropriate objects.
Once I made clean and build it started to fail when loading nib since stale files were removed by clean.
Once I fixed the nib name in code everything started to work smoothly.
Thanks for the replies, they showed me the right way. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.