按下UIAlert按钮后更改故事板

时间:2014-01-05 14:49:23

标签: ios uiview storyboard

我想在UIAlert上点击主菜单后更改为主菜单

尝试这个:

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

之后面临黑屏

1 个答案:

答案 0 :(得分:1)

按钮索引从0开始,因此使用3个按钮,无法调用buttonIndex == 3分支。

来源:Apple Docs on UIAlertView