xcode 没有按钮的 UIAlertView 以及如何关闭它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13379398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIAlertView with NO buttons and how to close it
提问by Spire
I have activity indicator in alert view that I use until my app gets the server response. The app send data to server and the alert view shows, how to close it when the server sends me the response. Here is code from my alert
我在警报视图中有活动指示器,直到我的应用程序获得服务器响应为止。应用程序将数据发送到服务器,警报视图显示如何在服务器向我发送响应时关闭它。这是我的警报中的代码
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];
回答by iArezki
[alert dismissWithClickedButtonIndex:0 animated:YES];
回答by Samet DEDE
You can use MBProgressHUDinstead of standart UIAlertView for something like that.
您可以使用MBProgressHUD而不是标准 UIAlertView 来实现类似的功能。
回答by Midhun MP
You can use the dismissWithClickedButtonIndex:
delegate method for dismissing the alertView.
您可以使用dismissWithClickedButtonIndex:
委托方法来关闭 alertView。
[alert dismissWithClickedButtonIndex:0 animated:YES];
Make sure that alert
is declared on the @Interface
.
确保alert
在@Interface
.
dismissWithClickedButtonIndex:animated:
Dismisses the receiver, optionally with animation.
- (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.
animated
YES if the receiver should be removed by animating it first; otherwise, NO if it should be removed immediately with no animation.
Discussion
In iOS 4.0, you may want to call this method whenever your application moves to the background. An alert view is not dismissed automatically when an application moves to the background. This behavior differs from previous versions of the operating system, where they were canceled automatically when the application was terminated. Dismissing the alert view gives your application a chance to save changes or abort the operation and perform any necessary cleanup in case your application is terminated later. Availability
Available in iOS 2.0 and later.
Declared In UIAlertView.h
解雇WithClickedButtonIndex:动画:
关闭接收器,可选择使用动画。
- (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 中声明
Please refer UIAlertView
请参考UIAlertView