Skip navigation.
 
mlreplacing self in initWithCoder method?
FROM : Dan Wood
DATE : Wed Nov 27 21:54:06 2002

I have some UI elements in a nib that are subclasses of NSComboBox --
however, I would like to, via a preference, just show them as a plain
NSTextField instead.  (NSTextField happens to be a subclass of
NSComboBox.)

I'm thinking that maybe I can fake this in the initWithCoder: method of
MyComboBox, so that if the preference is set to use a plain NSTextField
instead, I replace self with an NSTextField.

However, it's not working (I end up seeing a combo box in the
interface, though it doesn't respond to the popup button.  And, I get
this message at runtime when the NSTextField is built:

   NSView not correctly initialized. Did you forget to call super?

Am I doing this wrong?  Any suggestions on making this work?

Dan



@implementation MyComboBox

- (id)initWithCoder:(NSCoder *)decoder
{
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   BOOL beTextField = [defaults boolForKey:@"Use Plain Text Field"];

   if (beTextField)
   {
       [self autorelease];    // don't need the MyComboBox that was allocated
       self = [[NSTextField alloc] initWithCoder:decoder];    // replace with
an NSTextField
   }
   else
   {
       if (self = [super initWithCoder:decoder])
       {
           .... MyComboBox - specific initialization
     }
    }
   return self;
}

--
Dan Wood
Karelia Software, LLC
<email_removed>
http://www.karelia.com/
Watson for Mac OS X: http://www.karelia.com/watson/
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlreplacing self in initWithCoder method? Dan Wood Nov 27, 21:54
mlRe: replacing self in initWithCoder method? Jérôme Laurens Nov 28, 09:27