Re: Outlets not allocated
Re: Outlets not allocated
- Subject: Re: Outlets not allocated
- From: Andy Lee <email@hidden>
- Date: Wed, 10 Jun 2009 15:10:34 -0400
On Wednesday, June 10, 2009, at 12:56PM, "Micha Fuhrmann" <email@hidden> wrote:
>Rajendran,
>
>Many thanks for your answer. You are right. Now there's something I
>don't understand in terms of sequence, at least it doesn't make sense
>to me. I instantiate the Object, why shouldn't I be able to send
>messages to contained objects?
A nib file describes a bunch of connected objects. When Cocoa loads the nib file, there are two things it has to do: (1) instantiate the objects (using alloc plus an appropriate init method) and (2) connect them (using setter methods where they exist, otherwise accessing ivars directly). At the time objects are being initted (i.e., inside your init method), the connections haven't been made yet. This means the outlets have not been set. The outlets are set in a separate stage, after all the objects being connected have been fully initted.
> How am I suppose to deal with the
>sequence?
That is exactly what awakeFromNib is for. After Cocoa (1) instantiates the objects and (2) connects them, it (3) sends awakeFromNib to them so they can do any initialization they have to do that has to be done after the connections have been made.
> I mean, I instantiate an object but the I can't dispose from
>it after.
What do you mean "dispose from it"? Can you show a code example of what you mean? What are you trying to do that would be "inefficient" in awakeFromNib as opposed to init?
--Andy
> How do you deal with that kind issue? I know I could set the
>string in objects and on awakeFromNib set the text fields, but it just
>seems inefficient. Any tricks?
>
>Michael
>
>On 10 juin 09, at 18:30, email@hidden wrote:
>
>>
>> Hi,
>> oulets are not allocated on initiate . Its guaranteed to be
>> allocated only on awakeFromNib . Any message to outlet should be
>> sent from awakeFromNib and not from init method.
>>
>>
>>
>> Regards
>> Rajendran P
>>
>> -----Original Message-----
>> From: cocoa-dev-bounces+rajendran_pichaimurthy=email@hidden
>> [mailto:cocoa-dev-bounces+rajendran_pichaimurthy=email@hidden
>> ] On Behalf Of Micha Fuhrmann
>> Sent: Wednesday, June 10, 2009 9:40 PM
>> To: Cocoa List
>> Subject: Outlets not allocated
>>
>> Hi there,
>>
>> It's been hours and really I don't get it. I've got a custom
>> NSWindowController class. I'm loading it with a Nib. That Nib
>> contains a window and text fields in it all linked through outlets
>> to my NSWindowController class. When I allocate and initiate the
>> window appears fine, but when I send a message to fill in the text
>> fields nothing happens. If I set a breakpoint I can see that none of
>> my outlets are allocated (0x0 under the value column). Why aren't
>> they allocated and initiated when the Nib is loaded?
>>
>> Any help greatly appreciated.
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>_______________________________________________
>
>Cocoa-dev mailing list (email@hidden)
>
>Please do not post admin requests or moderator comments to the list.
>Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
>Help/Unsubscribe/Update your Subscription:
>
>This email sent to email@hidden
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden