• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: initWithCoder in Nib object loading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initWithCoder in Nib object loading


  • Subject: Re: initWithCoder in Nib object loading
  • From: Jonathan Hess <email@hidden>
  • Date: Fri, 27 Jun 2008 10:30:09 -0700

Hey John -

If you're thinking about overriding initWithCoder: just to do post NIB loading instantiation, I would recommend overriding awakeFromNib instead. The objects in the NIB are sent the initWithCoder: message because they're actually being decoded from an archive. Conceptually initWithCoder: should be used to implement the NSCoding protocol, and it should be paired with encodeWithCoder:. If you're custom view/ object isn't actually going to implement the NSCoding protocol, I think you should override awakeFromNib instead. The reason some obejcts get init, and some get initWithFrame: and others get initWithCoder: is that objects like the 'blue cube' in IB, or the 'custom view' are typically placeholders for classes from your project that aren't available in IB, and might not implement NSCoding. So, after 'blue cube' or 'custom view' objects are unarchived, with initWithCoder:, they replace themselves with objects of the classes you specified in IB. The create those instances with an alloc message followed by either an init or initWithFrame:.

Good Luck -
Jon Hess

On Jun 27, 2008, at 4:28 AM, John Murphy wrote:

I notice that there are a couple different init methods used for nib loading. For instance, objects from the IB Library get an initWithCoder message, while custom view objects get an initWithFrame, and everything else gets an init. Why is this? Specifically, why a special initWithCoder technique? After all, isn't everything encoded?



_______________________________________________

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


References: 
 >initWithCoder in Nib object loading (From: John Murphy <email@hidden>)

  • Prev by Date: Re: Layer Backed Views and CoreAnimation neither animate nor stay in place
  • Next by Date: Losing some event
  • Previous by thread: Re: initWithCoder in Nib object loading
  • Next by thread: Core data question in multiwindow doc app
  • Index(es):
    • Date
    • Thread