No known class method for selector scene? [duplicate]

瘦欲@ 提交于 2019-12-13 06:20:06

问题


Possible Duplicate:
Error “No known class method for selector 'Hello:'” in custom-made framework

I am creating a Main menu for my game here It does not compile but i do not understand why

//  Main Menu.m
//
//
//

#import "MainMenu.h"
#import "CCTouchDispatcher.h"
#import "Instructions.h"

CCSprite *seeker1;
CCSprite *cocosGuy;

@implementation MainMenu


+ (CCScene *) scene
{
    CCScene * scene = [CCScene node]; // scene is an autorelease object
    MainMenu * layer =  [MainMenu node]; // later is an autorelease object
    [scene addChild: layer]; // add layer as a child to scene
    return scene; // return the scene
}

- (id) init
{
    if ( ( self = [super init] ) )
    {
        [ self setUpMenus ];
    }
    return self;
}

- (void) setUpMenus
{

    // create menu items

    CCMenuItemImage * startButton = [CCMenuItemImage itemFromNormalImage:@"startbutton.png"
                                                           selectedImage:@"startbutton_selected.png"
                                                                  target: self
                                                                selector: @selector (doSomethingOne:)];


    CCMenuItemImage * instructionsButton = [CCMenuItemImage itemFromNormalImage:@"instructionsbutton.png"
                                                                  selectedImage:@"instructionbutton_selected.png"
                                                                         target: self
                                                                       selector: @selector(doSomethingTwo:)];


    CCMenuItemImage * unlockList = [CCMenuItemImage itemFromNormalImage: @"unlocklist.png"
                                                          selectedImage:@"unlocklist_selected.png"
                                                                 target: self
                                                               selector: @selector(doSomethingThree:)];

    // create the menu and add the items to it
    CCMenu * myMenu = [CCMenu menuWithItems: startButton, instructionsButton, unlockList,nil];


    // arrange the items vertically
    [myMenu alignItemsVertically];


    // add the menu to the scene
    [self addChild:myMenu];

}


- (void) doSomethingOne: (CCMenuItem *) menuItem
{


}

- (void) doSomethingTwo: (CCMenuItem  *) menuItem
{
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionFade transitionWithDuration:0.5f scene:[Instructions scene] ]];
}

- (void) doSomethingThree: (CCMenuItem  *) menuItem
{

}


@end

Why do I get the error that there is No known class method for the selector scene? regarding doSomethingTwo. Do I have to import something in the .h file? or an implementation? Thank you for any help you can provide me.


回答1:


Does the Instructions class implement this selector?

+(id) scene
{
   id scene = [CCScene node];
   return scene;
}

And does the Instruction class' interface declare this selector so other classes can reference it?

@interface Instructions : CCLayer
{
}

+(id) scene;

@end

You need both.




回答2:


From the code you posted + (CCScene *) scene is the MainMenu class method and you are calling it from Instructions which probably doesn't have a method with the same signature.



来源:https://stackoverflow.com/questions/11856483/no-known-class-method-for-selector-scene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!