2

我有一个警报:

UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Connection Failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

我想知道当我在代码中遇到某个事件时如何以编程方式关闭警报视图。我知道关闭警报没有明显的呼叫,而且我看到人们直接呼叫按钮,但是,我不确定如何在警报上调用取消按钮。

这甚至是正确的方法吗?还是有更好的路径?

4

2 回答 2

4

您可以使用-dismissWithClickedButtonIndex:animated:关闭警报视图的方法:

[connectionError dismissWithClickedButtonIndex: connectionError.cancelButtonIndex
                                      animated: YES];

这是唯一用于解除警报的公共 API,因此您应该使用它。

于 2012-10-15T14:10:36.557 回答
1

在 .h 文件中声明您的警报视图

然后调用这个函数

[connectionError dismissWithClickedButtonIndex:0 animated:YES];

希望能帮助到你..

于 2012-10-15T14:11:56.820 回答