Re: Overiding NSButton initWithFrame: (doesn't work)
Re: Overiding NSButton initWithFrame: (doesn't work)
- Subject: Re: Overiding NSButton initWithFrame: (doesn't work)
- From: email@hidden
- Date: Sat, 2 Feb 2002 10:58:21 -0800
Now I remember running into the same dilemma before. Its best not to
duplicate code in multiple places yet there is no single init function
which is guaranteed to be called. Some initialization needs to take
place no matter whether the instance was progromatically created or
decoded from a nib. What is the most elegant solution?
Off the top of my head its probably best to call my own universal init
routine from awakeFromNib, initWithFrame, and initWithCoder if I want to
ensure that the same block of code is always used for
initialization.Yes?
If you do it from both -initWithCoder and -awakeFromNib it will be
called twice, I believe. This is a perfect example of the sort of
initialization that does not belong in -awakeFromNib, IMHO.
And yes, calling a shared initialization method (after calling super's
init method) seems like the best way to handle this, and I've done this
many times in my code.
Ben Haller
Stick Software