fatal error: method declaration not in @interface context
这个错误是什么意思?以下是我的代码。但我没看出有什么问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | -(id) init { if( (self=[super init] )) { CGSize winSize = [[CCDirector sharedDirector] winSize]; CCSprite *player = [CCSprite spriteWithFile:@"Player.png" rect:CGRectMake(0, 0, 27, 40)]; player.position = ccp(player.contentSize.width/2, winSize.height/2); [self addChild:player]; } if( (self=[super initWithColor:ccc4(255,255,255,255)] )) { } return self; } |
如果您在@interface a€| 之外编写属性或方法声明,则会出现此错误。 @end 块,特别是如果您将它放在@interface 之前或@end 之后。这是一个会导致此错误的示例:
1 2 3 4 5 6 7 8 9 10 11 | @interface MyClass : NSObject { // instance vars here } // properties and method declarations here @end // ERROR: method declared outside @interface (after @end) -(void) someMethodWithObject:(id)obj; |