gpt4 book ai didi

ios - 使用 UI 警报 View 按钮关闭模态视图 Controller

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

我对 Xcode 有点陌生。现在我正在创建一个 View Controller (以模态方式显示),它显示一个表单供用户输入信息,然后单击“提交”来提交信息。

我创建了 IBAction,并实现了一个 UIAlerView 来通知用户信息已发送。我希望警报 View 中的“确定”按钮将它们带回原始 View Controller 。我设置了 Alert View delegate 并在 .m 文件中实现了以下方法:

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

当我测试它时,没有任何反应。谁能告诉我我做错了什么。

最佳答案

您需要实现 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 委托(delegate)方法 ---

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//dissmiss here
//Pre iOS 6.0
[self dismissModalViewControllerAnimated:YES];

//From iOS 5.0
[self dismissViewControllerAnimated:YES completion:nil];
}

您还可以检查点击的按钮,

if(buttonIndex != [alertView cancelButtonIndex]) {
//do something
}

关于ios - 使用 UI 警报 View 按钮关闭模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200508/

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