문제

그래서 나는 "mazecell.h"로 선언 된 Mazecell이라는 수업이 있습니다.

#import <Foundation/Foundation.h>

enum {
    MazeCellEdgeWall = 0,
    MazeCellEdgeGate = 1,
    MazeCellEdgeExit = 2
};
typedef NSUInteger MazeCellEdge;

@interface MazeCell : NSObject {
    MazeCellEdge left;
    MazeCellEdge right;
    MazeCellEdge down;
    MazeCellEdge up;
    NSUInteger drawCount;
    NSUInteger row;
    NSUInteger column;
}
@property MazeCellEdge left;
@property MazeCellEdge right;
@property MazeCellEdge down;
@property MazeCellEdge up;
@property NSUInteger drawCount;
@property NSUInteger row;
@property NSUInteger column;

- (id)initWithLeft:(MazeCellEdge)newLeft
             right:(MazeCellEdge)newRight
                up:(MazeCellEdge)newUp
              down:(MazeCellEdge)newDown
               row:(NSUInteger)newRow
            column:(NSUInteger)newColumn;
@end

Xcode는 다음과 같은 경고를 계속 표시합니다 "warning: 'MazeView' may not respond to '-left'" 모든 방법에 대해. 재미있는 점은 시뮬레이터에서 코드가 잘 실행된다는 것입니다. Xcode가 메소드를 알지 못한다는 것입니다.

Xcode가 내가 사용할 수 없을 때까지 메시지를 무시하는 데 만족했습니다. MazeCellEdgeWall 이전에 선언되지 않았기 때문에 (이 모든 경고와 오류는 다른 클래스에 있습니다).

그래서 나는 일반적으로 프로그래밍을 처음 접했기 때문에 누군가가 놓친 뻔뻔스러운 오류를 보았는지 궁금했습니다.


편집하다: 원래 코드가 길기 때문에 코드를 포함하지 않았지만 여기에 코드가 오류가 발생합니다.

다음은 "mazecell.m"입니다.

#import "MazeCell.h"

@implementation MazeCell

@synthesize left;
@synthesize right;
@synthesize down;
@synthesize up;
@synthesize drawCount;
@synthesize row;
@synthesize column;

-(id) init {
    if (self = [super init]) {
        right = MazeCellEdgeWall;
        up = MazeCellEdgeWall;
        left = MazeCellEdgeWall;
        down = MazeCellEdgeWall;
        drawCount = 0;
    }
    return self;
}

- (id)initWithLeft:(MazeCellEdge)newLeft
             right:(MazeCellEdge)newRight
                up:(MazeCellEdge)newUp
              down:(MazeCellEdge)newDown
               row:(NSUInteger)newRow
            column:(NSUInteger)newColumn
{
    if (self = [super init]) {
        left = newLeft;
        right = newRight;
        up = newUp;
        down = newDown;
        drawCount = 0;
        row = newRow;
        column = newColumn;
    }
    return self;
}
@end

여기 mazeview.h :

#import "MazeView.h"
#import "MazeCell.h"
#import "NSMutableArray+Stack.h"

#define kCellSidesSize 80.0

@implementation MazeView

@synthesize maze;
@synthesize controller;
@synthesize interfaceOrientation;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        interfaceOrientation = UIInterfaceOrientationPortrait;
        [self setBackgroundColor:[UIColor greenColor]];
        [self setUserInteractionEnabled:YES];
        [self setMaze:[[Maze alloc] initWithSize:MazeSizeMake(4, 6)]];
    }
    return self;
}

- (void)setMaze:(Maze *)newMaze {
    maze = newMaze;
    CGRect newFrame = [self frame];
    newFrame.size = CGSizeMake([newMaze size].width * kCellSidesSize,
                               [newMaze size].height * kCellSidesSize);
    [self setFrame:newFrame];
}

- (void)setInterfaceOrientation:(UIInterfaceOrientation)newOrientation {
    if (interfaceOrientation != newOrientation) {
        interfaceOrientation = newOrientation;
        CGRect oldFrame = [self frame];
        [self setFrame:CGRectMake(oldFrame.origin.y, oldFrame.origin.x,
                                  oldFrame.size.height, oldFrame.size.width)];
        [[self superview] setContentSize:[self frame].size];
    }
}

- (void)setController:(UIViewController *)newController {
    if (controller != newController) {
        controller = newController;
    }
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    NSUInteger columns = [[self maze] size].width;
    NSUInteger rows = [[self maze] size].height;

    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, kCellSidesSize - 2.0);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    CGContextSetLineCap(context, kCGLineCapRound);

    BOOL isDrawing = NO;
    MazeCell *aCell;
    NSMutableArray *aStack = [[NSMutableArray alloc] init];
    NSUInteger row = 0;
    NSUInteger column = 0;

    while (YES) {
        aCell = [maze getCellInRow:row andColumn:column ofOrientation:interfaceOrientation];

        if (isDrawing) {
            CGContextAddLineToPoint(context, row * kCellSidesSize + kCellSidesSize / 2.0,
                                          column * kCellSidesSize + kCellSidesSize / 2.0);
        } else {
            isDrawing = YES;
            CGContextMoveToPoint(context,  row * kCellSidesSize + kCellSidesSize / 2.0,
                                        column * kCellSidesSize + kCellSidesSize / 2.0);
        }

        if ([aCell left] == MazeCellEdgeExit && [aCell drawCount] < 1) {
            //Warnings and errors
            [aCell setDrawCount:1];  //Warning
            column--;
        } else if ([aCell right] == MazeCellEdgeExit && [aCell drawCount] < 2) {
            //Warnings and errors
            [aCell setDrawCount:2];  //Warning
            column++;
        } else if ([aCell up] == MazeCellEdgeExit && [aCell drawCount] < 3) {
            //Warnings and errors
            [aCell setDrawCount:3];  //Warning
            row--;
        } else if ([aCell down] == MazeCellEdgeExit && [aCell drawCount] < 4) {
            //Warnings and errors
            [aCell setDrawCount:4];  //Warning
            row++;
        } else if ([aStack count] > 0) {
            aCell = [aStack pop];
            row = [aCell row];       //Warning
            column = [aCell column]; //Warning
            isDrawing = NO;
        } else {
            break;
        }
    }
    CGContextStrokePath(context);
    [aStack release];
}

@end

다시, 이것은 내가 물건을 코딩했음을 증명하기 위해 제공됩니다. 이 프로그램은 작동하고, MazecellEdgeExit을 정의하지 않았고 더 이상 컴파일하지 않는다는 것을 제외하고는 Xcode가 내가 신경 쓰지 않을 경고를주는 것은 실제로 작동합니다. 그러나 그렇지 않으면 컴파일합니다.


이제 이것은 매우 이상합니다. 그러나 나는 mazecell.h와 mazecell.m 파일을 복제하고 mzcell.h 및 mzcell.m으로 바꾸고 Mazecell에 대한 모든 참조를 Mzcell으로 바꾸면이 프로그램이 실행되었다는 것을 알게되었습니다.

그것은 대답보다 더 많은 질문을 열지 만 ...

도움이 되었습니까?

해결책

모든 것이 나에게 좋아 보인다. 깨끗하고 빌드를 시도하십시오. 구식 객체 파일이 떠 다니면서 컴파일러 나 링커를 혼동 할 수 있습니다.

SetMaze : Old Maze를 해제하지 않는 곳과 같이 많은 명백한 메모리 누출이 있지만 컴파일을 방해하는 버그를 감지 할 수 없었습니다. (당신은 분명히 -initwithframe에서 미로를 할당합니다. 따라서 적어도 그 중 하나를 누출합니다.) 또한 기본 세터 의미 론적은 "고정"또는 "복사"가 아닌 "할당"입니다. 후자의 두 가지 행동은 더 의미가 있습니다. 나는 당신이 Objective-C를 처음 접한다는 것을 알고 있습니다. 그래서 이것들은 비판이 아니라 건설적인 피드백의 의미입니다. :-)

다른 팁

실제로 경고를 생성하는 코드를 포함하지 않지만 어디에서나 Mazecell.h 헤더 파일을 가져 오지 않은 것 같습니다.

당신이 할당하고 시작하는 객체 ( 'mazeview')가 'mazecell'객체가 아닐 수도 있습니다. 이것은 척이 언급 한대로 mazecell.h를 가져 오거나 단순히 잘못된 클래스를 가진 'mazeview'객체를 만드는 것을 무시함으로써 발생할 수 있습니다. Mazecell 유형의 객체를 만들고 'mazeview'라고 이름을 지정하는 것은 직관적입니다).

또한 Xcode에 테스트하기 위해 지금 액세스 할 수는 없지만 TypEdef가 잘못 선언 될 수 있다고 생각합니다 (또는 그 구문 스타일에 익숙하지 않음). typedef의 6 줄을 이것으로 교체하십시오.

typedef enum {
    MazeCellEdgeWall = 0,
    MazeCellEdgeGate = 1,
    MazeCellEdgeExit = 2
} MazeCellEdge;

편집하다:구현 파일을 방금 포함 시켰으므로 Mazeview (7 행)를위한 것이지만 원래 헤더 파일은 Mazecell입니다. 따라서 현재로서는 실제로 Mazecell 객체에 대한 코드 (또는 게시되지 않은)를 작성하지 않았습니다.

또한 인스턴스 변수 중 하나를 합성 (또는 작성한 방법)하지 않은 것으로 의심됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top