gpt4 book ai didi

ios - 在 UIAlertView 中按下按钮后继续

转载 作者:行者123 更新时间:2023-11-29 10:57:02 25 4
gpt4 key购买 nike

我正在开发一个应用程序,当我在 UIAlertView 中按下“OK”按钮时,我需要在其中显示一个 ViewController。我该怎么做?

我在这里找到了这个解决方案:iOS Dev: Segue by pressing a button in an Alert? ,但它没有用。

xCode 说:

the method: presentModalViewController is deprecated

我在网上发现我应该使用 presentViewController 方法。

我尝试这样做,但显示黑屏,没有任何互动,这是怎么回事?我把我的代码贴在这里,也许你能帮我。

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
PromoViewController *pvc = [[PromoViewController alloc] init];
[self presentViewController:pvc animated:YES completion:nil];
}
}

谢谢

最佳答案

为了以编程方式使用 segue,您需要调用 performSegueWithIdentifier

首先确保您的 segue 在 Storyboard中有一个标识符。

然后改用这段代码...

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
[self performSegueWithIdentifier:@"YourSegueIdentifier"];
}
}

这会做你想做的事。

关于ios - 在 UIAlertView 中按下按钮后继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17788106/

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