通过编码实现关闭警告

得到的警告:

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

我想知道能不能编程关闭打开特定事件时的警告视图。我知道没有特定的调用。但是我记得有些人在按钮上直接调用但是怎么取消警告?

使用-dismissWithClickedButtonIndex:animated:。这个方法可以取消警告视图。

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

这是关闭警告的接口。

现在.h文件中声明警告视图

然后调用这个方法:

[connectionError dismissWithClickedButtonIndex:0 animated:YES];

希望能帮到你