So I created a class CommonMethods with class method:
+ (CCMenu *)createMenu:(NSString *)menuName atPosition:(CGPoint)position {
CCMenuItemImage *menuBlock = [CCMenuItemImage itemWithNormalImage:menuName selectedImage:menuName target:self selector:@selector(choose:)];
CCMenu *menuBlockMenu = [CCMenu menuWithItems:menuBlock, nil];
menuBlockMenu.position = position;
return menuBlockMenu;
}
Now in my MainClass which contains choose: method, I create a menu:
CCMenu *regularBlockMenu = [CommonMethods createMenu:kbRegularBlock atPosition:position];
[self addChild:regularBlockMenu];
My program crashes when I tap the menu because it doesn’t understand selector call. How do I implement this? I want to create a CommonMethods method because I will use this method over and over in many classes.
Thanks for your help.
You want to have a method choose in class MainClass? if so, you need modify your createMenu function a bit. Try this,
then in MainClass:
and you need to define
-(void)choose:(id)sender;in MainClassSo what this is doing is setting the target of choose: to be an instance of MainClass, rather than CommonMethods.