gpt4 book ai didi

ios - 按下 UIAlert 按钮后更改 Storyboard

转载 作者:行者123 更新时间:2023-11-29 03:22:09 24 4
gpt4 key购买 nike

我想在游戏中通过 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] 之后面临黑屏

最佳答案

按钮索引从 0 开始,因此对于您的 3 个按钮,buttonIndex == 3 分支无法被调用。

来源:Apple Docs on UIAlertView

关于ios - 按下 UIAlert 按钮后更改 Storyboard ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20934928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com