gpt4 book ai didi

ios - 如果 被弃用,我如何让我的警报按钮执行操作?

转载 作者:搜寻专家 更新时间:2023-10-30 20:14:08 26 4
gpt4 key购买 nike

我们曾经在 ViewController.h 中使用 UIAlertViewDelegate 让我们的自定义警报按钮执行一个操作,比如在警报窗口中按下 Play Again 按钮使游戏重新开始。

我们如何使用 UIAlertController(UIAlertView 的替代类)做到这一点?

我阅读了 Apple 提供的以下文档,没有看到提到的委托(delegate)方法。这是否意味着我们不再这样做了?

https://developer.apple.com/reference/uikit/uialertcontroller

最佳答案

  • 首先添加UIAlertController

  • 然后添加UIAlertAction

  • 然后将该操作添加到您的警报 Controller

如下所示。

UIAlertController *myalert = [UIAlertController alertControllerWithTitle:@"your title" message:@"your messate" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *myaction = [UIAlertAction actionWithTitle:@"you title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//your action here
}];


[myalert addAction:myaction];
[self presentViewController:myalert animated:YES completion:nil];

关于ios - 如果 <UIAlertViewDelegate> 被弃用,我如何让我的警报按钮执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39559749/

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