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)] )) |
- 你不应该设置两次 self 更不用说两次调用 init 了。如果您在代码中的其他任何地方执行此操作,则需要撤消它并重新考虑您的逻辑。
- 我同意上面的乔。还有哪一行给你错误?
- 学习正确地格式化你的代码会有很大帮助。
- 我看不出调用两个不同的 super init… 方法有什么意义。您是否意识到 “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) |
来源:https://www.codenong.com/9777782/