I’m stumped. I don’t have any errors or even warnings. I set a breakpoint at the line that calls it, and the program stops there, but when I set a breakpoint inside the actual code for that selector, the program doesn’t stop. The selector I’m concerned with is toggleCellAtX:Y:. Here’s SPPuzzle.m:
#import "SPPuzzle.h"
@implementation SPPuzzle
- (id)init
{
self = [super init];
if (self) {
int x, y;
for (y=0; y<3; y++)
for (x=0; x<3; x++) {
cells[x][y] = FALSE;
}
}
return self;
}
- (BOOL)cellOnAtX:(int)x Y:(int)y {
return cells[x][y];
}
- (void)toggleCellAtX:(int)x Y:(int)y {
cells[x][y] = !cells[x][y]; // Breakpoint here doesn't stop program.
}
@end
And here’s SPPuzzleView.m:
#import "SPPuzzleView.h"
@implementation SPPuzzleView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
puzzleInstance = [[SPPuzzle alloc] init];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
int x, y;
for (y=0; y<3; y++)
for (x=0; x<3; x++) {
if ([puzzleInstance cellOnAtX:x Y:y]) {
[[NSColor greenColor] set];
} else {
[[NSColor redColor] set];
}
[[NSBezierPath bezierPathWithRect:NSMakeRect(100*x, 100*y, 100, 100)] fill];
[[NSColor blackColor] set];
[[NSBezierPath bezierPathWithRect:NSMakeRect(100*x, 100*y, 100, 100)] stroke];
}
}
- (void)mouseDown:(NSEvent *)theEvent {
int x = (int)[theEvent locationInWindow].x / 100;
int y = (int)[theEvent locationInWindow].y / 100;
[puzzleInstance toggleCellAtX:x Y:y]; // Breakpoint here does stop program.
[self setNeedsDisplay:TRUE];
}
@end
I added comments to show where the breakpoints are. What am I doing wrong?
By the way, I used Step Into on the invocation of the method, but it just goes to the next line ([self setNeedsDisplay:TRUE];).
puzzleInstanceis probablynil(0x0in the watch list, as you noted:nilis just another fancy name for the memory address0). This would be the case if you instantiated yourSPPuzzleViewfrom a XIB file, because the loading mechanism callsinitWithCoder:(thenawakeFromNib) instead ofinitWithFrame:, leaving yourpuzzleInstanceuninitialized.