Re: Q: Designated initializers: what are they?
Re: Q: Designated initializers: what are they?
- Subject: Re: Q: Designated initializers: what are they?
- From: Ali Ozer <email@hidden>
- Date: Sat, 12 May 2001 11:00:14 -0700
On Saturday, May 12, 2001, at 10:14 AM, Ali Ozer wrote:
There can be multiple designated initializers. It turns out that
initWithCoder: is also an (implicit?) designated initializer for
classes which archive. Thus, classes which override the DI init...
methods would need to override initWithCoder: as well if they want to
unarchive themselves.
So one solution is to call your common initialization from both
initWithCoder: and initWithFrame:. If you're concerned about
initWithCoder: just because of IB unarchiving (which is almost always
the case for custom views; you normally do not archive them otherwise),
then as Henri says you can use awakeFromNib instead of overriding
initWithCoder:.
Of course right after posting this I remembered that initWithFrame:
should still be called for custom subclasses of NSView in IB which are
instantiated as views in IB; initWithCoder: is called in some less
common cases. Sounds to me like your case is the common case, which
should have been going through initWithFrame:. But you said
initWithFrame: wasn't called at all?
Ali