Ios 按下UIAlert按钮后更改情节提要

Ios 按下UIAlert按钮后更改情节提要,ios,uiview,storyboard,Ios,Uiview,Storyboard,我想在点击游戏主菜单后切换到主菜单 试一试: -(void)gameOver { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Time's up!" message:[NSString stringWithFormat:@"You've scored: %i points!", scoreCounter]

我想在点击游戏主菜单后切换到主菜单

试一试:

    -(void)gameOver
{
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Time's up!"
                          message:[NSString stringWithFormat:@"You've scored: %i points!", scoreCounter]
                          delegate:self
                          cancelButtonTitle:nil
                          otherButtonTitles:@"Submit to Leaderboards",@"Play Again",@"Main Menu", nil];
    [alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        [self toMain];
    }
    if (buttonIndex == 2) {
        [self toMain];
    }
    if (buttonIndex == 3)
    {
        [self toMain];
    }

}
-(void)toMain
{
    mainMenu *main = [[mainMenu alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:main animated:YES completion:NULL];
}
什么都不做

编辑


修正了按钮索引,现在在[self toMain]

按钮索引从0开始后将面临黑屏,因此对于您的3个按钮,无法调用
buttonIndex==3
分支


来源:

您是否在
*.h
文件中添加了
协议
?明确声明协议不会影响任何事情,但这是一个好主意。索引0处的取消按钮不是吗?thx,现在它确实做了一些事情,现在我在[self toMain]之后面临一个黑屏,那是什么?@powerj1984他的取消按钮是nil@MartinJ这是一个不同的问题。