I'm trying to subclass NSTokenField
and I need to setup some ivars during initialisation but I can't work which initialiser I have to override. The documentation doesn't say anything about the designated initialisers of NSTokenField
or NSTextField
which the token field inherits from.
I tried overriding -initWithFrame:
and -init:
but they don't get called either.
It should be either initWithFrame:
, if you create the text field in your code, or initWithCoder:
if the field is created in an XIB (Interface Builder) file.
This is because NSTokenField
inherits from NSView
, which conforms to the NCoding
protocol. So this is also valid for other objects inheriting from NSView
.
So basically, you should override both in a subclass:
- ( id )initWithFrame: ( NSRect )frame;
- ( id )initWithCoder: ( NSCoder * )decoder;