• 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: devil of a time with an NSImageView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: devil of a time with an NSImageView


  • Subject: Re: devil of a time with an NSImageView
  • From: Jonathan Hess <email@hidden>
  • Date: Thu, 20 Aug 2009 12:21:05 -0700

c. A couple of weeks ago on this list, one of our Apple experts (Luke, maybe, but I can't remember for sure) said to use the more specialized method (such as 'windowDidLoad') *instead of* the generic 'awakeFromNib', if the class has it.

I missed that thread. Do you happen to know some keywords from the subject?

While I was looking for this thread, I found this old answer from an other Cocoa expert (Chris Hanson):


http://lists.apple.com/archives/cocoa-dev/2003/Jul/msg00260.html

I'm quoting the conclusion:

“I prefer to use -awakeFromNib only to finish configuring controls themselves, while I prefer to populate them in -windowDidLoad (or its NSDocument equivalent). Why? Because they're conceptually two different thing. The first is essentially to make up for a lack of Interface Builder palettes to finish configuring your view objects -- for instance, being able to set an NSTableView's double-click action, or configuring a data cell for a table column -- while the second involves gluing your model objects to your view objects."

Another reason to prefer a method like viewDidLoad, or windowDidLoad to awakeFromNib is that awakeFromNib can potentially be called twice on the same object. For example, if you have a window controller, and that window controller loads its main NIB file, it will get an awakeFromNib message. If that window controller later manually loads a second nib file, to present a sheet for example, it will have awakeFromNib sent to it a second time since it's the file's owner of the NIB file. This second awakeFromNib invocation usually comes as a surprise.


I recommend using awakeFromNib to do things like configure an object that awakes from a nib, but doesn't care which particular NIB it is. For example, if I had a MyView, and I represented it in nib files with a "Custom View", and I want them all to start out with their enabled boolean set to YES, I would implement awakeFromNib on MyView to set the property to YES. Now, if one of my specific windows controllers had a NIB with an instance of MyView in it, and it wanted that instance to be initially disabled, I would configure that in the window controller's windowDidLoad method.

Jon Hess

_______________________________________________

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: 
 >Statements in Replaced Method execute out of sequence - How? (From: Jerry Krinock <email@hidden>)
 >devil of a time with an NSImageView (From: Jack Carbaugh <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Dave DeLong <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jack Carbaugh <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Quincey Morris <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jack Carbaugh <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jean-Daniel Dupas <email@hidden>)
 >Re: devil of a time with an NSImageView (From: "I. Savant" <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jean-Daniel Dupas <email@hidden>)
 >Re: devil of a time with an NSImageView (From: "I. Savant" <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jean-Daniel Dupas <email@hidden>)
 >Re: devil of a time with an NSImageView (From: "I. Savant" <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Quincey Morris <email@hidden>)
 >Re: devil of a time with an NSImageView (From: "I. Savant" <email@hidden>)
 >Re: devil of a time with an NSImageView (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Accessing method from another class
  • Next by Date: Re: NSSortDescriptor in core-data document app
  • Previous by thread: Re: devil of a time with an NSImageView
  • Next by thread: Re: devil of a time with an NSImageView
  • Index(es):
    • Date
    • Thread