Unrecognized Selector when I click on CCMenuItemImage

244 views Asked by At

I'm trying to load a start menu for a game, and I've added a play button using a CCMenuItemImage. Everything loads just fine. However, when I try to click on the play button, I get this error message.

013-08-18 13:38:46.091 PeevedPenguins-iOS[5169:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[StartMenuLayer ]: unrecognized selector sent to instance 0x9e5b400'

I don't know what I'm doing wrong since my selector is defined and all. Please help me out? I've been pulling my hair out trying to figure out why Xcode would do this

@interface StartMenuLayer ()

@end

@implementation StartMenuLayer

-(id) init
{
    if ((self = [super init]))
    {
        CCMenu *myMenu = [CCMenu menuWithItems: nil];

        CCMenuItemImage *menuBackground = [CCMenuItemImage itemWithNormalImage:@"menu-background-hd.png" selectedImage:@"menu-background-hd.png" target:self selector:nil];
        [myMenu addChild:menuBackground];

        CCMenuItemImage *menuPlayButton = [CCMenuItemImage itemWithNormalImage:@"button-hd.png" selectedImage:@"button-hd.png" target:self selector:@selector(playGame:)];
        menuPlayButton.position = ccp(0, 0);
        [myMenu addChild:menuPlayButton];

        CCMenuItemImage * menuItem3 = [CCMenuItemImage itemWithNormalImage:@"catapult-hd.png"
                                                             selectedImage: @"catapult-hd.png"
                                                                    target:self
                                                                  selector:@selector(doSomethingThree:)];
        [myMenu addChild: menuItem3];

        menuPlayButton.position = ccp(0,-83.5);

        [self addChild:myMenu];
    }

    return self;
}

-(void) playGame:(CCMenuItem *)sender
{
//    [[CCDirector sharedDirector] replaceScene: (CCScene*)[[GameLayer alloc] init]];
    NSLog(@"Play the game!");
}

- (void) doSomethingThree:(CCMenuItem *)sender
{
    NSLog(@"The third menu was called");
}

@end
1

There are 1 answers

2
jlehr On BEST ANSWER

You configured one of your menu items with a nil selector [line breaks added for clarity]:

CCMenuItemImage *menuBackground = [CCMenuItemImage
                                  itemWithNormalImage:@"menu-background-hd.png"
                                  selectedImage:@"menu-background-hd.png" 
                                  target:self
                                  selector:nil];