Good evening all,
I'm trying to code a menu, but I keep getting
Thread 1: Program received signal: "SIGABRT".
My code is minimal at the moment, just trying to get it to work!
@implementation Menu
+(id)scene{
CCScene *scene = [CCScene node];
CCLayer *layer = [Menu node];
[scene addChild:layer];
return scene;
}
-(id)init{
if((self = [super init])){
CCLabelTTF *playLabel = [CCLabelTTF labelWithString:@"Play" fontName:@"Marker Felt" fontSize:40];
CCMenuItemLabel *play = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(doPlay:)]; //Th开发者_开发技巧is is where SIGABRT happens//
menu = [CCMenu menuWithItems:play, nil];
[self addChild:menu];
}
return self;
}
-(void)doPlay{
CCLOG(@"doPLay");
}
@end
Any help would be greatly appreciated :) There seems to be quite little on coding menus without images.
First order of business:
- Go to Build Settings
- Locate the compiler warning flag "Undeclared Selector"
- Set it to YES
This will catch a lot of similar errors, and I really don't understand why this setting isn't turned on by default in all Xcode projects.
Let me explain what your error is, it's easy to overlook without that warning enabled. The selector passed to menu item is this:
@selector(doPlay:)
The selector that's implemented is this:
-(void) doPlay
{
}
They don't match! The menu item is expecting a selector that takes one parameter, as denoted by the : (colon). Change selector to this:
@selector(doPlay)
You'll be fine. Next time, the compiler will warn you about that mishap.
精彩评论