Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Subclassing NSControls: What am I doing wrong?

Subclassing NSControls: What am I doing wrong?
Thread Tools
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Nov 23, 2002, 08:55 PM
 
Some time ago, Rickster posted a tip about engraved text, mentioning that a good way to do it was to subclass NSTextFieldCell and draw it slightly differently, etc. Since I was bored recently and have never subclassed an control before, I thought I'd try that out. Here's my code:
Code:
@implementation EngravedTextFieldCell - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view { NSLog(@"drawing engraved text"); [self setTextColor:[NSColor whiteColor]]; [super drawInteriorWithFrame:frame inView:view]; frame.origin.y++; [self setTextColor:[NSColor blackColor]]; [super drawInteriorWithFrame:frame inView:view]; } @end @implementation EngravedTextField + (Class)cellClass { NSLog(@"setting cell class"); return [EngravedTextFieldCell class]; } @end
I have in my nib an EngravedTextField.. but neither of my NSLogs is ever called. What am I doing wrong?
[vash:~] banana% killall killall
Terminated
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 24, 2002, 05:57 PM
 
It's not very obvious, but apparently you need to set the cellClass during initialization and no later. So, add this to EngravedTextField:
Code:
+ (void)initialize; { if (self == [EngravedTextField class]) [self setCellClass: [EngravedTextField Cell class]]; }
Rick Roe
icons.cx | weblog
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2