当我只添加一个MenuItem时,它工作正常。但是当我去另外两个MenuItem时,它会因异常'NSInvalidArgumentException'而崩溃,原因是:'+ [NSInvocation invocationWithMethodSignature:]:方法签名参数不能为nil'
我正在做什么
CCMenuItem *startGame = [CCMenuItemImage itemFromNormalImage:@"start-game.png" selectedImage:@"start-game.png" target:self selector:@selector(startGame:)];
CCMenuItem *settings = [CCMenuItemImage itemFromNormalImage:@"settings.png" selectedImage:@"settings.png" target:self selector:@selector(settings:)];
CCMenuItemImage *gameCentre = [CCMenuItemImage itemFromNormalImage:@"game-centre.png" selectedImage:@"game-centre.png" target:self selector:@selector(gameCentre:)];
CCMenu *menu = [CCMenu menuWithItems:startGame, settings, gameCentre, nil];
[menu alignItemsVerticallyWithPadding:10];
[self addChild:menu z:1];
CCMenuItem *startGame = [CCMenuItemImage itemFromNormalImage:@"start-game.png" selectedImage:@"start-game.png" target:self selector:@selector(startGame:)];
CCMenuItem *settings = [CCMenuItemImage itemFromNormalImage:@"settings.png" selectedImage:@"settings.png" target:self selector:@selector(settings:)];
CCMenuItemImage *gameCentre = [CCMenuItemImage itemFromNormalImage:@"game-centre.png" selectedImage:@"game-centre.png" target:self selector:@selector(gameCentre:)];
CCMenu *menu = [CCMenu menuWithItems:startGame, settings, gameCentre, nil];
[menu alignItemsVerticallyWithPadding:10];
[self addChild:menu z:1];
这是我的选择器功能
-(void)startGame:(id)sender
{
NSLog(@"start game");
}
-(void)setttings:(id)sender
{
NSLog(@"settings");
}
-(void)gameCentre:(id)sender
{
NSLog(@"game centre");
}
提前填写任何帮助
答案 0 :(得分:0)
您的选择器功能(startGame,settings,gameCentre)似乎写得不正确。
答案 1 :(得分:0)
因为您的选择器以“:”结尾,即@selector(gameCentre :),请确保您班级中的方法实际上采用参数
- (void)startGame:(id)sender
{
// do whatever you want here
}
- (void)settings:(id)sender
{
// do whatever you want here
}
- (void)gameCentre:(id)sender
{
// do whatever you want here
}
答案 2 :(得分:0)
您的选择器可能没有采用任何参数,而您提到“@selector(startGame:)
”就好像他们正在使用参数一样。如果他们不接受任何参数,它可能像“@selector(startGame)
”。你需要检查..