• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
drawRect using a Category
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: drawRect using a Category
      • From: David Duncan <email@hidden>
    • Re: drawRect using a Category
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Displaying an arbitrary unicode character using CGContextShowTextAtPoint or CGContextShowGlyphsAtPoint
  • Next by Date: Re: drawRect using a Category
  • Previous by thread: Re: Returning a specific key's value for all members of a dict in an array.
  • Next by thread: Re: drawRect using a Category
  • Index(es):
    • Date
    • Thread