drawRect using a Category
drawRect using a Category
- Subject: drawRect using a Category
- From: Peter Teeson <email@hidden>
- Date: Fri, 30 Mar 2012 23:31:45 -0400
Xcode 4.3 Lion 10.7.3
In a Document app I have an NSMatrix. I only need to override drawRect.
Rather than using a sub-class, which seems overkill to me,
I decided to try a Category instead. So here's what I did (and it seems to work.)
But since this is the first time I've tried such a thing I'm asking
your thoughts, advice, etc in case I'm on the wrong track.
Here are my code snippets:
Using Control drag from the xib to the Document.h I added
@property (weak) IBOutlet NSMatrix *matrix;
and manually typed in
@interface NSMatrix (Draw)
-(void)drawRect:(NSRect)dirtyRect;
@end
In Document.m I added
@implementation NSMatrix (Draw)
-(void)drawRect:(NSRect)dirtyRect
{
// some drawing stuff
}
@end
This allows me to add whatever calls to drawRect I wish from
within methods in Document.m
What do you think of this approach? Is there a more elegant way?
TIA and respect….
Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden