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 8309449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:07:16+00:00 2026-06-08T19:07:16+00:00

I am using cocos2d for developing. I have tried to wrap a customized button

  • 0

I am using cocos2d for developing. I have tried to wrap a customized button class. When trying to make the button respond to the selector I assigned to it, I used NSInvocation. In it, the MyButton works like this.

if( target && sel ) {
            sig = [target methodSignatureForSelector:sel];
            invocation_ = nil;
            invocation_ = [NSInvocation invocationWithMethodSignature:sig];
            [invocation_ setTarget:target];
            [invocation_ setSelector:sel];
            [invocation_ setArgument:&self atIndex:2];
            [invocation_ retain];
        }

I have passed the sel a function like this:

- (void)onButtonClicked:(id)sender;

my question is: does it necessary to add this line [invocation_ setArgument:&self atIndex:2]; in MyButton’s implementation?

I have this question is because according to ios documentation here:
NSInvocation Class Reference

it addressed that:

Indices 0 and 1 indicate the hidden arguments self and _cmd,
respectively; you should set these values directly with the setTarget:
and setSelector: methods. Use indices 2 and greater for the arguments
normally passed in a message.

it seems that self has been passed when calling setTarget, does it mean that, the &self argument is not necessary to be passed in setArgument method?

Thanks

  • 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-06-08T19:07:18+00:00Added an answer on June 8, 2026 at 7:07 pm

    The documentation just tell that the first argument (with indice 0) represent the target object (so the “self”). As the documentation explains you the first argument is set using the setTarget: method.

    You need to keep this line of code [invocation_ setArgument:&self atIndex:2]; to send the button’s reference to the target-action pair.

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

Sidebar

Related Questions

I'm using cocos2d with objective C. I have a class called CrystalineBubble that is
I'm developing an app using cocos2d and box2d phisycs. I whant to make my
i'm using cocos2d, however the question is general. i have a class CCNode *scaleLayer
I am developing an iphone game using cocos2d and have it set to to
I am developing a game on Iphone using cocos2d. I have a CClayer containing
I am using cocos2d-x with Lua for development. Recently I used Instruments and have
I'm developing a game using cocos2d v2.0 beta2. Since i worked with iOS5.0 all
I am developing ' Paper Toss' for iphone using cocos2d & I would like
I am developing an interactive 2-book for children using cocos2D framework. It would be
I am currently developing a card game for the iphone using cocos2d. I am

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.