3

在我的应用程序获得服务器响应之前,我在警报视图中有活动指示器。该应用程序将数据发送到服务器,并且警报视图显示,当服务器向我发送响应时如何关闭它。这是我的警报中的代码

        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];
4

3 回答 3

7
[alert dismissWithClickedButtonIndex:0 animated:YES];
于 2012-11-14T13:07:24.460 回答
1

你可以使用MBProgressHUD而不是标准的 UIAlertView 来做类似的事情。

于 2012-11-14T13:12:26.377 回答
0

您可以使用dismissWithClickedButtonIndex:委托方法来关闭 alertView。

[alert dismissWithClickedButtonIndex:0 animated:YES];

确保alert@Interface.

dismissWithClickedButtonIndex:动画:

关闭接收器,可选择使用动画。

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

按钮索引

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 中,您可能希望在应用程序移至后台时调用此方法。当应用程序移到后台时,警报视图不会自动关闭。此行为与以前版本的操作系统不同,后者在应用程序终止时会自动取消。关闭警报视图使您的应用程序有机会保存更改或中止操作并执行任何必要的清理,以防您的应用程序稍后终止。可用性

Available in iOS 2.0 and later.

在 UIAlertView.h 中声明

请参考UIAlertView

于 2012-11-14T13:10:35.790 回答