2012-10-15 93 views
2

我有一個警告:關閉警報視圖通過代碼

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

我想知道我怎麼能編程關閉警報視圖,當我在我的代碼打一個特定的事件。我知道沒有截然不同的呼叫來關閉警報,而且我看到有人直接撥打電話按鈕,但是,我不確定如何在警報上調用取消按鈕。

這是甚至正確的方式去呢?還是有更好的途徑?

+1

哈,沒錯。實際上,我正在掃描地毯下的成功並顯示錯誤。我只是使用錯誤警報作爲我的例子。 – Max

回答

4

可以使用-dismissWithClickedButtonIndex:animated:方法解僱警報視圖:

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

這是解僱的警報唯一的公共API,所以你應該使用它。

+0

輝煌。謝謝。 – Max

1

聲明你的警報視圖中.h文件中

然後調用這個函數

[connectionError dismissWithClickedButtonIndex:0 animated:YES]; 

希望它可以幫助..