NSView puzzle
NSView puzzle
- Subject: NSView puzzle
- From: DKJ <email@hidden>
- Date: Thu, 9 Oct 2008 13:17:47 -0700
I'm having trouble with a subclass of NSView.
In the code below, the variable str is an NSString set to a constant
string when the view is initialised. During initialisation the NSPoint
variable click is set to 0,0.
When the view first displays, str is drawn correctly in the lower-left
corner, just as you would expect. But when I click in the view, I get
a bad access error. The error occurs when str is told to draw itself
for the second time, in the line I've marked with ***.
I can't understand what could be happening here. According to the
debuggerer, str, click, and dict all have valid values at that point.
=== CODE ===
- (void)drawRect:(NSRect)rect {
NSImage *board = [[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"chessboard"
ofType:@"tiff"]];
[board drawInRect:[self bounds]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:0.5];
*** [str drawAtPoint:click withAttributes:dict];
}
- (void)mouseDown:(NSEvent *)ev {
click = [self convertPoint:[ev locationInWindow] fromView:nil];
[self display];
}
_______________________________________________
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