Re: Subclassing NSTextView
Re: Subclassing NSTextView
- Subject: Re: Subclassing NSTextView
- From: "Michael Ash" <email@hidden>
- Date: Wed, 13 Aug 2008 12:09:17 -0400
On Tue, Aug 12, 2008 at 9:15 PM, John Joyce
<email@hidden> wrote:
> Ooops, nevermind!!
> I answered my own question.
> When adding the class file to the project, start with the NSView subclass
> template, then change it to subclass NSTextView in the .h
> and in the .m either call [super drawRect:rect]; or comment out or delete
> the drawRect method all together.
> That was too stupidly easy to be obvious.
> Too bad there is not an option for more subclass templates right in the GUI
In most cases, all you need to create a minimal, functional subclass is this:
@interface MyClass : SuperClass {} @end
@implementation MyClass @end
In other words, just a plain empty class with no methods and no ivars,
inheriting from the class you want.
This is all due to the idea of OO programming. You inherit all of the
behavior of the superclass. If you provide no further behavior, then
you act exactly like that superclass.
There is one big exception to this. If the superclass is actually an
abstract class with private concrete subclasses (which is to say that
doesn't implement all of its functionality on its own) then there will
be required functionality that any subclass must implement. In Cocoa
these are generally called class clusters, documented as such, and the
required subclass functionality listed (the required methods are
called primitive methods).
It's unlikely for an NSView to be a class cluster (it's *possible*,
but I know of no examples of such) so for any NSView you subclass, you
can just start with a blank slate as above.
Mike
_______________________________________________
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