@interface TextViewPoser : NSTextView @end // TextViewPoser @implementation TextViewPoser - (void) drawRect: (NSRect) bounds { NSLog (@"drawRect"); [super drawRect: bounds]; } // drawRect @end // TextViewPoserThen in your
main.m
(or somewhere convenient)[[TextViewPoser class] poseAsClass: [NSTextView class]];
@implementation NSView (BWYellowView) - (void) drawRect: (NSRect) rect { NSColor *transparentYellow; rect = [self bounds]; transparentYellow = [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: 0.0 alpha: 0.333]; [transparentYellow set]; [NSBezierPath fillRect: rect]; } // rect
NSString *identifier = [aTableColumn identifier]; Person *person = [employees objectAtIndex: rowIndex]; return ([person valueForKey: identifier]);Why is this cool? By changing the value of the identifier, you can change the field of the Person object you'll be accessing. e.g. you can change which part of the object you're manipulating in Interface Builder and not have to recompile code. Also, it lets you avoid having to write (and maintain) the nasty idiom of
if (identifier is "oop") { return (person.oop); } else if (identifier is "ack") { return (person.ack); } ...
- (BOOL)respondsToSelector: (SEL)aSelector { NSString *methodName = NSStringFromSelector (aSelector); NSLog (@"respondsToSelector: %@", methodName); return ([super respondsToSelector: aSelector]); } // respondsToSelector