Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 25, 2009, 09:53 AM   #1
aliher
macrumors newbie
 
Join Date: Mar 2009
Location: UK
Instantiation of objects in IB

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:owner: 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.
aliher is offline   0 Reply With Quote
Old Mar 25, 2009, 01:50 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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?
kainjow is offline   0 Reply With Quote
Old Mar 25, 2009, 01:57 PM   #3
aliher
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: 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.
aliher is offline   0 Reply With Quote
Old Mar 25, 2009, 02:00 PM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Mar 25, 2009, 02:03 PM   #5
aliher
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: 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.
aliher is offline   0 Reply With Quote
Old Mar 25, 2009, 02:07 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Maybe you forgot to set the class of the object and it's still an NSObject or something..
kainjow is offline   0 Reply With Quote
Old Mar 26, 2009, 05:21 AM   #7
aliher
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: 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.
aliher is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
lazy instantiation grandM iPhone/iPad Programming 4 Apr 28, 2014 12:35 PM
Objects in Objective C luke71933 Mac Programming 6 Apr 8, 2014 09:20 AM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 13, 2013 12:24 AM
Desktop objects removed ? Mellthorn Mac Basics and Help 6 Nov 28, 2012 02:18 PM
LR -> PS as smart objects patent10021 Digital Photography 1 Oct 17, 2012 04:44 PM

Forum Jump

All times are GMT -5. The time now is 10:34 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC