Hi all!
Given
@interface Canvas:NSView {
NSNumber * currentToolType;
...
}
declared in my .h file and in the .m file
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
currentToolType=[[NSNumber alloc]initWithInt:1];
}
return self;
}
and further down
-(void)mouseUp:(NSEvent *)event
{
NSLog(@"tool value in event: %d",[currentToolType intValue]);
//rest of code
}
-(NSBezzierPath *)drawPath:(NSRect)aRect
{
NSLog(@"tool value in draw: %d",[currentToolType intValue]);
//rest of drawPath method code that uses the value of currentToolType in a switch statment
}
-(IBAction)selectToolOne:(id)sender
{
[currentToolType release];
[currentToolType = [[NSNumber alloc]initWithInt:0];
}
-(IBAction)selectToolTwo:(id)sender
{
[currentToolType release];
[currentToolType = [[NSNumber alloc]initWithInt:1];
}
The action methods are the only place where currentToolType
is changed. But, for some reason, it seems to be a different instance of currentToolType
in the mouseUp
. I did not write (or synthesize) accessors for the var as it is used only by itself. I noticed that initWithFrame
is called twice - I'm assuming it's for the parent window and the NSView?
What am I missing?
THANKS!
This is an XCode generated Document based app using COCOA and Obj-C. I'm new at both.