• 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: Q: Designated initializers: what are they?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q: Designated initializers: what are they?


  • Subject: Re: Q: Designated initializers: what are they?
  • From: Henri Lamiraux <email@hidden>
  • Date: Sat, 12 May 2001 09:47:27 -0700

Post nib loading initialization should be done in -awakeFromNib. Although -initWithCoder is being called when an object is instantiated from a nib it is usually to early: outlets and targets/actions have not yet been connected at this point.

- (void)commonInit
{
// put your common initiatization code here
}

- (id)initWithFrame:(NSRect)frame // Call when your object is allocated programmatically
{
self = [super initWithFrame:frame];
[self commonInit];
return self;
}

- (void)awakeFromNib // Called when your object is instantiated from a nib
{
[self commonInit];
}

On Saturday, May 12, 2001, at 12:45 AM, email@hidden wrote:


I've just spent way too much trying to debug a problem which is probably due to my lack of fundamental understanding of Cocoa, so I'm seeking enlightenment.

I wrote a custom NSView for which I wanted to implement drag and drop. It failed to receive drops because it turned out that the object never received the registerForDraggedTypes: message I was sending it from my initWithFrame: method, because this method was never called. Instead initWithCoder: was called, which I did not think to implement.

Now, the reason for my confusion is that initWithFrame: is supposed to be the "designated initializer" for the NSView class. Doesn't that mean that that's the one method that's always going to be called eventually, no matter what other initializers get called? Since that's (apparently) not the case, what does it mean to be a "designated initializer"? And am I supposed to duplicate my initialization code in every possible initializer, i.e. initWithFrame: and initWithCode:, or is there a more elegant solution?

Arno.

PS: anybody at Apple had a look at the problems with NSTextView I posted about earlier this week. Ali? Chuck? Andrew? Anyone?
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev


Henri Lamiraux
Engineering Manager
User Interface Tools Group
Apple


References: 
 >Q: Designated initializers: what are they? (From: email@hidden)

  • Prev by Date: Re: Q: Designated initializers: what are they?
  • Next by Date: Re: Q: Designated initializers: what are they?
  • Previous by thread: Re: Q: Designated initializers: what are they?
  • Next by thread: Re: Q: Designated initializers: what are they?
  • Index(es):
    • Date
    • Thread