2012-11-14 162 views
3

我有警報視圖中的活動指示符,我使用它直到我的應用程序獲得服務器響應。應用程序向服務器發送數據,警報視圖顯示服務器向我發送響應時如何關閉它。下面是代碼從我的警報帶有NO按鈕的UIAlertView以及如何關閉它

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Canceling reservation" message:@"please wait" delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; 
     [alert show]; 

     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

     // Adjust the indicator to place at the bottom of the dialog window. 
     indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-50); 
     [indicator startAnimating]; 
     [alert addSubview:indicator]; 

回答

7
[alert dismissWithClickedButtonIndex:0 animated:YES]; 
+1

它的工作原理。 Thx很多 – Spire

+0

歡迎您 – iArezki

+1

+1快速回復:) –

0

可以使用dismissWithClickedButtonIndex:委託方法駁回alertView。

[alert dismissWithClickedButtonIndex:0 animated:YES]; 

確保alert是在@Interface聲明。

dismissWithClickedButtonIndex:動畫:

駁回接收機,任選地與動畫。

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated Parameters

buttonIndex

The index of the button that was clicked just before invoking this method. The button indices start at 0. 

動畫

YES if the receiver should be removed by animating it first; otherwise, NO if it should be removed immediately with no animation. 

討論

在iOS中4.0,你可以由W螞蟻在您的應用程序 移動到後臺時調用此方法。當應用程序移動到後臺時,警報視圖不會自動解除 。此行爲與以前版本的操作系統 不同,它們在應用程序終止時自動取消 。關閉 警報視圖讓您的應用程序有機會保存更改,或者 放棄操作並執行任何必要的清理,以防您的應用程序稍後終止。可用性

Available in iOS 2.0 and later. 

宣佈UIAlertView.h

請參閱UIAlertView

1

可以使用MBProgressHUD代替非標準UIAlertView中類似的東西。

相關問題