我目前在我的cocos2d应用程序中有一个场景,它有一个UIAlertView提醒用户,如果他们开始新游戏,它将删除旧游戏。一旦他们承认这一点,就应该转换到游戏场景。单击“是”按钮时出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSCFNumber count]: unrecognized selector sent to instance 0xa81afc0'
以下是代码:
-(id) init
{
CCMenuItemSprite *newMenuItem = [CCMenuItemSprite itemWithNormalSprite:new
selectedSprite:newSelected
disabledSprite:nil
target:self
selector:@selector(onPlayClicked:)];
CCMenu *menu = [CCMenu menuWithItems:nil];
if ([name length] > 0) {
[menu addChild:contMenuItem];
}
[menu addChild:newMenuItem];
[menu addChild:optionMenuItem];
[menu alignItemsVertically];
menu.position = ccp(winSize.width/2, winSize.height - (winSize.height * 0.70));
[self addChild:menu z:1];
}
- (void)onPlayClicked:(id)sender
{
[[SimpleAudioEngine sharedEngine] playEffect:@"button.mp3"];
NSString *name = [[GameManager sharedGameManager] getName];
if ([name length] > 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure?" message:@"Starting a new game will delete your old game" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];
[alert show];
} else {
[[CCDirector sharedDirector] replaceScene:[PlayScene scene]];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
[[GameManager sharedGameManager] resetGameState];
[[CCDirector sharedDirector] replaceScene:[PlayScene scene]];
}
}