我收到一条警报:
UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Connection Failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
我想知道当我在代码中遇到某个事件时如何以编程方式关闭警报 View 。我知道没有明确的调用来关闭警报,并且我见过人们直接调用按钮,但是,我不确定如何调用警报上的取消按钮。
这是否是正确的做法?或者有更好的途径吗?
最佳答案
您可以使用 -dismissWithClickedButtonIndex:animated:
方法来关闭警报 View :
[connectionError dismissWithClickedButtonIndex: connectionError.cancelButtonIndex
animated: YES];
这是唯一用于消除警报的公共(public) API,因此您应该使用它。
关于iphone - 通过代码关闭警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12897392/