どのように私はiPhoneでCocos2dレイヤにUIAlertViewを表示することができますか?

StackOverflow https://stackoverflow.com/questions/1913102

質問

私は私のゲームで層を持っています。ゲームの仕上げで、私は、ユーザーに再起動したり、ゲームを終了するため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];
} 
役に立ちましたか?

解決

あなたのコードのクラッシュはないか、それだけで表示されない?

あなたがラインに若干の誤差があります。

[[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]

注:最後のパラメータは、可変長引数であり、したがって無記号が終了する必要があります。

他のヒント

ディレクターは、それが動作する可能性があり、一時停止される前に

alertviewを表示するようにしてください..

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top