I am trying to subclass NSView but to no avail.
I have an empty window with a simple menu (which I will care about it later) and then I try to subclass NSView. To do that, I click on: File, New, File... I click on Objective-C class and then click on Next. After "Class" I type: DrawingView. After "Subclass of" I type: NSView. Two new files DrawingView.h and DrawingView.m are created.
I update the files as follows:
DrawingView.h:
DrawingView.m:
But the method drawRect is not called. What am I missing?
I have an empty window with a simple menu (which I will care about it later) and then I try to subclass NSView. To do that, I click on: File, New, File... I click on Objective-C class and then click on Next. After "Class" I type: DrawingView. After "Subclass of" I type: NSView. Two new files DrawingView.h and DrawingView.m are created.
I update the files as follows:
DrawingView.h:
Code:
//
// DrawingView.h
// Drawing
//
// Created by Hans Kamp on 25-03-13.
// Copyright (c) 2013 Hans Kamp. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface DrawingView : NSView
- (void) drawRect:(NSRect)frame;
@end
DrawingView.m:
Code:
//
// DrawingView.m
// Drawing
//
// Created by Hans Kamp on 25-03-13.
// Copyright (c) 2013 Hans Kamp. All rights reserved.
//
#import "DrawingView.h"
@implementation DrawingView
- (void) drawRect:(NSRect)frame {
[[NSColor redColor] set];
[NSBezierPath fillRect:frame];
}
@end
But the method drawRect is not called. What am I missing?
Last edited: