How to send Method's name for elements
I'm making method to make button easily. but I don't know how to send method's name.. which is a button have to be called when user press this button. Is there any way to send this name?
I want to k开发者_如何学Pythonnow "???????????????????"part on my source below..
this source is part of "Support.m" which I'm making. Thanks..
+ (id)CreateButton:(id)layer (NSString*)filename secondfilename:(NSString*)filename2 sameimage:(BOOL)sameimage position:(CGPoint)position
{
CCSprite *sprite1 = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:filename]];
CCSprite *sprite2 = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:filename2]];
CCSprite *sprite1 = [CCSprite spriteWith
CCMenuItem *MenuItem = [CCMenuItemImage itemFromNormalSprite:sprite1 selectedSprite:sprite2 target:layer selector:@selector(???????????????????????????????)];
MenuItem.position = position;
CCMenu *Menu = [CCMenu menuWithItems:MenuItem, nil];
Menu.position = CGPointZero;
return Menu;
}
Just put the name of the method which you want to be called when that menu item is selected:
CCMenuItem *MenuItem = [CCMenuItemImage itemFromNormalSprite:sprite1
selectedSprite:sprite2
target:layer
selector:@selector(methodToRunWhenMenuItemIsSelected:)];
Whatever object the target is, in this case layer
then needs to have a method of that name implemented:
- (void) methodToRunWhenMenuItemIsSelected: (CCMenuItem *)item {
// Do something interesting
}
精彩评论