Subclassing question
Subclassing question
- Subject: Subclassing question
- From: John Scalo <email@hidden>
- Date: Wed, 22 Jan 2003 22:28:30 -0800
I want to subclass NSView so that it has a setVisible: method. Say I call it
HidingView. The details of doing that are no problem, but how do I go about
making things that are already subclasses of NSView (e.g.
NSProgressIndicator, NSImageView, etc) inherit from this subclass rather
than NSView? Sure I could subclass those subclasses every time and take care
of things there, but it sure would be convenient if I could just have all
subclasses of NSView inherit from HidingView so I could hide things when I
need to. Categories are almost perfect except...no instance variables. What
am I missing?
PS here's the simple subclass
- (void)setVisible:(BOOL)b
{
if (!b)
{
if (![self isVisible])
return;
savedFrame = [self frame];
[self setFrame:zeroFrame];
[self setNeedsDisplay:YES];
}
else
{
if ([self isVisible])
return;
[self setFrame:savedFrame];
[self setNeedsDisplay:YES];
}
}
- (BOOL)isVisible
{
NSRect visRect = [self visibleRect];
return (visRect.size.width != 0);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.