Subclass Programmatically Added NSButton?
I have a bunch of programmatically created NSButtons in my app. How can I go about setting the subclass of these NSButtons without us开发者_C百科ing Interface Builder?
When you create the button, don't create them as NSButtons, create them as your subclass. For example, if you had a subclass of NSButton
called MyButton
, instead of something like:
NSButton *button = [[NSButton alloc] initWithFrame:frame];
You would have something like:
MyButton *button = [[MyButton alloc] initWithFrame:frame];
This way button
will be an instance of MyButton
.
精彩评论