views:

170

answers:

2

I have an instance of a class "A" in my EAGLView class, it gets instantiated in the EAGLView's initWithCoder method.

This class "A" contains an IBOutlet to a UIView.

I also have an instance of this class "A" in the Interface Builder, to connect the class "A" IBOutlet to the corresponding view.

So the class "A" is being instanciated twice, the first time by the Interface Builder, where the in the awakeFromNib method, the IBOutlet is working perfectly. However it's getting instanciated again by EAGLView, and this time the outlet that connects to the UIView is obviously not connected to a UIView so it's nil.

What could I do from a design perspective to avoid this problem ? , I really tried to be very clear hope it's clear enough.

+2  A: 

Don't instantiate class "A" from your EAGLView's initWithCoder: method. The NIB loader is already creating this instance for you; you shouldn't be creating it again. Is there a reason you feel you need to create it in initWithCoder:?

Rob Napier
Is there a way I could use the instance made by the NIB loader instead of creating another instance ? That class needs to sort stuff and modify the original UIView, when the user performs some actions.
Mr.Gando
You use the instance made by the NIB loader by wiring an IBOutlet to it. I thought you said you already had access to the NIB instantiated object through the IBOutlet?
Rob Napier
A: 

Instead of instantiating "A" the second time in code, you probably want to create an IBOutlet for your "A" class in your EAGLView class, and connect that up in Interface Builder.

Dan Messing
It's a possibility , but EAGLView doesn't have a proxy instance in IB, and if it had, I would end getting multiple instances of EAGLView. ( which is instanciated in my ApplicationDelegate class.
Mr.Gando