Re: Overriding NSTextField problem
Re: Overriding NSTextField problem
- Subject: Re: Overriding NSTextField problem
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 25 Feb 2002 15:30:08 -0800
On Sunday, February 24, 2002, at 02:03 AM, Cyril Godefroy wrote:
Hi,
I'm overriding NSTextField to have a different behavior for
drag&drop. What I did is create a new MyTextFied:NSTextField
class, then in IB I imported that class and set my textfield's
custom class to MyTextField.
I have an init message which basically does:
if (self = [super init]){
NSLog(@"MyTextField");
[self registerForDraggedTypes:[NSArray
arrayWithObject:NSStringPboardType]];
}
return self;
I don't see the Log appearing.
So, I wonder what is wrong with what I've done. Hints or
answers are welcome....
(Short answer)
To register your text field for dragging events:
- (void) awakeFromNib
{
[self registerForDraggedTypes:[NSArray
arrayWithObject:NSStringPboardType]];
}
(More detailed answer)
The problem is that under these conditions, your -init method is
never called.
First of all, NSView's designated initializer is -initWithFrame:
not -init. Secondly, when objects are unarchived from a nib
file, they get an -initWithCoder: message, not -initWithFrame:.
(Effectively, they get their -initWithFrame: message only once,
and that's when they get created in IB.)
Another thing to watch out for when using custom subclasses of
controls in IB, is that the custom NSActionCell subclass you
might write will never get instantiated, since IB will have
archived whatever cell the parent class uses.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.