How can I show UIAlertView on Cocos2d Layer in iPhone?
-
19-09-2019 - |
Question
I have a layer in my game. At finishing of game I want to show user an UIAlertView for restarting or quitting the game. But it is not working. I am also given the delegate UIAlertViewDelegate to layer.
Any Solutions?
My Code follows,
-(void)gameFinished{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[self unschedule:@selector(checkForCollision)];
[self unschedule:@selector(dropObject)];
[self stopBackgroundMusic];
[self startNewForegroundMusic:@"GameOver" ofType:@"caf"];
[self playForegroundMusic];
[[Director sharedDirector] pause];
UIAlertView *view=[[UIAlertView alloc] initWithTitle:@"Game Finished" message:@"Want to play again?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
[view show];
[view release];
}
Solution
Does your code crash, or does it just not display?
You do have a slight error in the line
[[UIAlertView alloc] initWithTitle:@"Game Finished"
message:@"Want to play again?"
delegate:self cancelButtonTitle:@"No"
otherButtonTitles:@"Yes"]
This should be
[[UIAlertView alloc] initWithTitle:@"Game Finished"
message:@"Want to play again?"
delegate:self cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", Nil]
note: the last parameter is variable argument, and thus should be Nil terminated.
OTHER TIPS
Try to show the alertview before the director is pause it may work..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow