Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

eddjc

macrumors newbie
Original poster
Apr 12, 2007
7
0
Hey all,

I'm having problem with NSView's initWithFrame class - it's the 'Dot View' app from "Learning Cocoa"'s examples - here's the source:

Code:
#import "DotView.h"


@implementation DotView

- (id)initWIthFrame:(NSRect)frame
{
	self = [super initWithFrame:frame];
	center.x = 50.0;
	center.y = 50.0;
	radius = 20.0;
	color = [[NSColor redColor] retain];
	return self;
}

- (void)awakeFromNib
{

// this line added to make it work	
color = [[NSColor redColor] retain];

	[colorWell setColor:color];
	[slider setFloatValue:radius];
}

- (void)dealloc
{
	[color release];
	[super dealloc];
}

- (void)drawRect:(NSRect)rect
{
	NSRect dotRect;
	
	[[NSColor whiteColor] set];
	NSRectFill([self bounds]);
	
	dotRect.origin.x = center.x - radius;
	dotRect.origin.y = center.y - radius;
	
	dotRect.size.width = 2 * radius;
	dotRect.size.height = 2 * radius;
	
	[color set];
	
	[[NSBezierPath bezierPathWithOvalInRect:dotRect] fill];
}

- (BOOL)isOpaque
{
	return YES;
}

- (void)mouseDown:(NSEvent *)event
{
	NSPoint eventLocation = [event locationInWindow];
	center = [self convertPoint:eventLocation fromView:nil];
	[self setNeedsDisplay:YES];
}

- (IBAction)setColor:(id)sender {
    NSColor * newColor = [sender color];
	[newColor retain];
	[color release];
	color = newColor;
	[self setNeedsDisplay:YES];
}

- (IBAction)setRadius:(id)sender {
    radius = [sender floatValue];
	[self setNeedsDisplay:YES];
}
@end

When I first built this app it threw back a *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: aColor != nil'

Then I added the line indicated above to make sure there was a value in colorWell and it built fine - the trouble being it wasn't initialized with the values in initWithFrame (Radius was set to 0) so it looks to me like either initWithFrame isn't loading, or awakeFromNib is loading first.

Any ideas?

Thanks

Edd
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.