나는 뒤죽박죽이다. 나는 어떤 오류 또는 경고도하지 않는다. 나는 그것을 호출하는 줄에 중단 점을 설정하고 프로그램이 멈추지 만, 그 선택자의 실제 코드 안에 중단 점을 설정하면 프로그램이 멈추지 않습니다. 걱정되는 셀렉터는 toggleCellAtX:Y:
입니다. 여기 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
을 그리고 것은 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
. 내가 도대체 뭘 잘못하고있는 겁니까?
그런데이 메소드를 호출 할 때 Step Into를 사용했지만 다음 줄 ([self setNeedsDisplay:TRUE];
)으로 넘어갑니다. (당신이 언급 한 바와 같이, 감시 목록에 0x0
: nil
는 메모리 주소 0
에 대한 또 다른 멋진 이름)
'puzzleInstance'가'nil'이 아닌지 확인하십시오. 이는 IIRC가'initWithFrame :'대신'initWithCoder :','awakeFromNib'를 호출하기 때문에 xib에서 뷰가 인스턴스화 된 경우에 발생합니다. 그것은 장거리지만, 작동한다면, 그냥 말하면 대답으로 다시 게시 할 것입니다. – zneak
@zneak 이것은 장황한 것이 아니라 거의 확실하게 문제입니다. – dasblinkenlight
그래, 그건 괜찮아, 내가 생각하는 건 감시 목록의 0x0가 무엇을 의미하는지. 알았다. 감사! – flarn2006