【问题标题】:Xcode 5 & Cocos2d: Random Errors Like: 'No Known Class Method for Selector 'scene'?Xcode 5 和 Cocos2d:随机错误,例如:'选择器'场景'的未知类方法?
【发布时间】:2014-05-03 20:08:54
【问题描述】:

我真的对 Obj-c 中出现的随机错误感到困惑? 以下是在另一个类中进行不相关的小改动后出现的错误。 此外,即使我撤消了添加到完全独立类的标题中的新布尔值,错误仍然存​​在!

有人可以在这里帮助我吗,因为我已经研究了一段时间的程序现在根本无法构建,而且我完全迷失了,因为我不知道编译器忽略了上述内容声明 CCScene '场景'...

感谢您的帮助

@implementation mainMenu

+(CCScene *)scene
{
CCScene *scene = [CCScene node];
mainMenu *layer = [mainMenu node];
[scene addChild: layer];
return scene;
}

- (void)loadAgainstTheClockMode:(id)sender
{
// Reload the current scene
CCScene *scene = [HelloWorldLayer scene];
[[CCDirector sharedDirector] replaceScene:[CCTransitionZoomFlipX     transitionWithDuration:0.2 scene:scene]];

屏幕截图... http://i.stack.imgur.com/DfrVB.png

【问题讨论】:

    标签: ios xcode cocos2d-iphone compiler-errors automatic-ref-counting


    【解决方案1】:

    您正在尝试在 HelloWorldLayer 类上调用 scene 方法。您指向当前类中的 +(CCScene *)scene 方法,但这不是 HelloWorldLayer 类。它在一个明确标记为mainMenu(应该大写)的类的类实现中。

    如果您打算调用提供的代码中的方法,您需要将您的代码更改为:

    CCScene *scene = [HelloWorldLayer scene];
    

    收件人:

    CCScene *scene = [mainMenu scene];
    

    CCScene *scene = [[self class] scene];
    

    HelloWorldLayer 类中创建一个scene 方法并将其声明放入其.h 文件中。

    【讨论】:

    • 是的,你是对的! - 不幸的是我搞砸了一点。毕竟我帖子中的代码是正确的。我现在意识到 HelloWorldLayer 类的场景由于某种原因从它的 .h 文件中丢失了……替换它已经解决了这个问题。我不知道为什么它不见了。另外,为什么 mainMenu 必须大写?再次感谢
    • 因为它是一个类,在 Objective-C 中,我们将类和小写的方法和变量大写。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多