0

我的游戏中有一层。在游戏结束时,我想向用户显示一个 UIAlertView 以重新启动或退出游戏。但它不起作用。我还获得了委托 UIAlertViewDelegate 进行分层。

任何解决方案?

我的代码如下,

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

2 回答 2

1

您的代码会崩溃,还是只是不显示?

您确实在行中有一个小错误

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes"]

这应该是

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes", Nil]

注意:最后一个参数是可变参数,因此应该以 Nil 终止。

于 2009-12-16T08:51:08.790 回答
-1

尝试在导演暂停之前显示警报视图,它可能会起作用..

于 2015-01-15T14:12:46.820 回答