Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:19:33+00:00 2026-05-27T21:19:33+00:00

I followed tutorial from cocos2d official site . I try to create some items

  • 0

I followed tutorial from cocos2d official site . I try to create some items for a menu when creating them i pass a selector with one parameter. For each item i pass different selector . I think here is the problem , but i dont see realy why here is the problem. My header file looks :

// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
#import "CCTouchDispatcher.h"

// HelloWorldLayer
@interface HelloWorldLayer : CCLayer {

    CCSprite *first;
    CCSprite *second;
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
- (void) setUpMenus;
- (void) doSomethingOne: (CCMenuItem  *) menuItem;
- (void) doSomethingTwo: (CCMenuItem  *) menuItem;
- (void) doSomethingThree: (CCMenuItem  *) menuItem;

@end

Implementation file :

// Import the interfaces
#import "HelloWorldLayer.h"

// HelloWorldLayer implementation
@implementation HelloWorldLayer

+(CCScene *) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];

    // 'layer' is an autorelease object.
    HelloWorldLayer *layer = [HelloWorldLayer node];

    // add layer as a child to scene
    [scene addChild: layer];

    // return the scene
    return scene;
}

- (void) doSomethingOne: (CCMenuItem  *) menuItem 
{
    NSLog(@"The first menu was called");
}
- (void) doSomethingTwo: (CCMenuItem  *) menuItem 
{
    NSLog(@"The second menu was called");
}
- (void) doSomethingThree: (CCMenuItem  *) menuItem 
{
    NSLog(@"The third menu was called");
}


// on "init" you need to initialize your instance
-(id) init
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) {

        first = [CCSprite spriteWithFile:@"seeker.png"];
        first.position = ccp(100, 100);

        [self addChild:first];

        second = [CCSprite spriteWithFile:@"Icon.png"];
        second.position = ccp(50, 50);

        [self addChild:second];

        [self schedule:@selector(nextFrame:)];

        [self setUpMenus];

        self.isTouchEnabled = YES;
    }

    return self;
}


- (void) registerWithTouchDispatcher {

    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

    return YES;
}

- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {

    CGPoint location = [self convertTouchToNodeSpace: touch];

    [second stopAllActions];

    [second runAction: [CCMoveTo actionWithDuration:1 position:location]];

}

- (void) nextFrame:(ccTime)dt {

    first.position = ccp( first.position.x + 100*dt, first.position.y );

    if (first.position.x > 480+32) {

        first.position = ccp( -32, first.position.y );
    }
}

- (void) setUpMenus {

    CCMenuItemImage *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"myfirstbutton.png" 
                                                        selectedImage:@"myfirstbutton_selected.png" 
                                                               target:self 
                                                             selector:@selector(doSomenthingOne:)];

    CCMenuItemImage *menuItem2 = [CCMenuItemImage itemFromNormalImage:@"mysecondbutton.png" 
                                                        selectedImage:@"mysecondbutton_selected.png" 
                                                               target:self
                                                             selector:@selector(doSomenthingTwo:)];
    CCMenuItemImage *menuItem3 = [CCMenuItemImage itemFromNormalImage:@"mythirdbutton.png" 
                                                        selectedImage:@"mythirdbutton_selected.png" 
                                                               target:self selector:@selector(doSomenthingThree:)];

    CCMenu *myMenu = [CCMenu menuWithItems:menuItem1,menuItem2,menuItem3, nil];

    [myMenu alignItemsVertically];

    [self addChild:myMenu];

}



// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
    // in case you have something to dealloc, do it in this method
    // in this particular example nothing needs to be released.
    // cocos2d will automatically release all the children (Label)

    // don't forget to call "super dealloc"
    [super dealloc];
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:19:34+00:00Added an answer on May 27, 2026 at 9:19 pm

    You’ve got the same typo in all three menu item creation calls. You’re telling the menu items that the selector they should use is called doSomenthing... (note the spurious n in the middle):

    CCMenuItemImage *menuItem1 = [...  selector:@selector(doSomenthingOne:)];
    CCMenuItemImage *menuItem2 = [...  selector:@selector(doSomenthingTwo:)];
    CCMenuItemImage *menuItem3 = [...  selector:@selector(doSomenthingThree:)];
    

    but the actual names of your methods are doSomethingOne:, doSomethingTwo:, and doSomethingThree:.

    The exact cause of the error message is that later, when the menu item needs to perform that selector, it will ask your class to tell it the method signature for the selector you gave it. Since you gave the item an incorrect selector, your class doesn’t know the signature, and it returns nil. The menu item tries to construct an NSInvocation object anyways to perform its action, which fails because the invocation can’t be created with a nil signature.

    Fix the typos and everything should work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed a tutorial to create a scrollbar template from this site: http://sachabarber.net/?p=122 But
I installed eclipse memory analyzer (mat) and followed the tutorial from the official site
I just downloaded the android sdk from the adnroid site and followed this tutorial
I followed the tutorial from this site: http://theappleblog.com/2008/08/04/tutorial-build-a-simple-rss-reader-for-iphone/ to make my first iPhone application,
I followed the Tutorial in Cocoa Programming For Mac OS X to create a
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
I am working on Windows Azure. I followed some tutorial about how to store
I've followed the tutorial from here: Twitter Client Tutorial to make a little twitter
i'm creating a lazy load of image in ListView. i was followed the tutorial
I've followed this tutorial for setting up a static library with common classes from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.