开发者

How can I show UIAlertView on Cocos2d Layer in iPhone?

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];
} 


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.


Try to show the alertview before the director is pause it may work..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜