Reputation: 45
I'm attempting to use a selector with arguments and failing while doing so. I'm coming from C/++ and selectors are a tad bit confusing. I have this code:
playItem = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(goToScene:)argumentHere];
How would I go about passing an argument to a method in this way?
Thanks in advance:D
Upvotes: 1
Views: 594
Reputation: 5887
Are you maybe looking for performSelector:withObject
? I'm afraid I don't quite understand your questions maybe.
Nikita is right, when you are setting up the selector you just pass in the descriptor name. Later in your code, when you call the method, you will pass in any arguments.
Upvotes: 0
Reputation: 67996
You can't. Selectors specify only method to be invoked, not parameters to be passed.
What you can do, is to check sender
parameter in your goToScene:
method. It's gonna be the element on which action is performed (most probably CCMenuItemLabel
in your case).
Thus, you can see which element was invoked (if you use goToScene:
for several ui elements) and decide which 'parameter' to use.
To tell different ui elements apart, tag
attribute is often used. So, code could look like
if ([sender tag] == 1) {
...
} else if ...
If you don't like too many ifs, lookup table will work.
Upvotes: 1