I have created a NSView
subclass called DAView
, incorporating an array of useful methods for later re-use. This works great, however, drawRect:
is never called in any classes that use DAView
, nor in the class itself. Why?
Here's how DAView
looks like:
DAView
@interface DAView : NSView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [NSColor clearColor];
// Make layer-backed by default
self.wantsLayer = YES;
// Create a root layer
CALayer *_rootLayer = [CALayer layer];
_rootLayer.shouldRasterize = YES;
_rootLayer.name = DAViewRootLayerDefaultName;
self.layer = _rootLayer;
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect // never called
{
NSLog(@"Draw Rect called");
}
Now, if I wanted to make use of this DAView's
additions/methods, I face the same problem. Everything works fine, except for drawRect:
, which, as in DAView
's case, is never called:
DATableView
@interface DATableView : DAView
- (void)drawRect:(NSRect)dirtyRect // never called either
{
[[NSColor grayColor] set];
NSBezierPath *_cellSeparator = [NSBezierPath bezierPath];
[_cellSeparator lineToPoint:dirtyRect.origin];
[_cellSeparator closePath];
[_cellSeparator stroke];
NSLog(@"Draw rect");
}
However If I change DATableView
's header to be a subclass of NSView
, drawRect:
is called.
What am I missing?