在模态视图中显示警报
问题描述:
我有一个显示模态视图的应用程序。在最后的模态视图中,我有一个表单。一旦点击完成按钮,就会调用一个Web服务,它传递从用户输入的值。收到回复后,模态视图被解除。我希望显示警报或操作表,要求用户等待,因为Web服务调用需要很长时间。问题在于警报或操作表只有在视图被解除后才会显示。这是为什么发生?以下是完成功能的代码:在模态视图中显示警报
-(void)reg:(id)sender {
if([password length] == 0) {
//show alert
}
//other validation
//This is were I write the alert
UIActivityIndicator *activity = [[UIActivityIndicator alloc] initWithActivityIndicatorStyle:
UIActivityIndicatorStyleWhite];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Processing" delegate:self otherButtonTitles:nil];
[alert addSubview:activity];
[activity startAnimating];
[alert show];
WebServiceController *web = [[WebServiceController alloc]init];
//webservice called
//getting the response
//dismissing alert here
[self dismissModalViewControllerAnimated:YES];
}
答
我明白了。这不是模态视图的问题。警报被阻止,因为主线程正在执行Web服务。 Web服务执行需要在后台运行。以下是与答案相似的问题的链接。
答
您必须为webservice响应编写监听器或通知。如果您使用的是NSUrlConnection,请使用其委托来获取响应并从委托方法中取消模态视图。在你使用的方法中,视图在调用web服务之后立即解散
+0
我没有得到你。我在web服务调用之前发出警报。它不应该显示警报,然后执行web服务调用? – 2011-03-08 11:48:13
您可以发布警报代码吗? – visakh7 2011-03-08 11:37:12