关于objective C:致命错误:方法声明不在 @interface 上下文中 | 珊瑚贝

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;
}

  • 你不应该设置两次 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)
(void) someMethodWithObject:(id)obj;


来源:https://www.codenong.com/9777782/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9943.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?