本文介绍了警报视图不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮,该按钮向 webservice 发送调用并返回一些值.我想显示一个没有按钮的警报框,直到值从 web 服务返回.但是 alertWait 在收到值后显示.我尝试使用设置警报功能并从按钮的开头调用,但这也显示在接收值的末尾.我哪里出错了,这是我的代码.
I have a button and the button sends a call to webservice and returns some values. I want to show an alert box without buttons until the value returns from webservice. But the alertWait is displaying after receiving the values. i tried using setting up a function for alert and calling in from the start of the button but that too displays at the end of receiving values. Where am i going wrong here is my code.
- (IBAction)UploadButton:(id)sender
{
// Initializtion of some elements
UIAlertView *alertWait;
alertWait = [[UIAlertView alloc] initWithTitle:@"Please Wait..."
message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alertWait show];
//Web service call statements
if ([status intValue] == 0)
{
NSLog(@"It is zero");
[alertWait dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert =[ [UIAlertView alloc]initWithTitle:@"Success" message:@"You have successfully uploded the document and waiting for approval" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
推荐答案
将服务调用放在后台线程上,就像下面更改的示例代码:
Put the service calls on a background thread, just like example code changed below :
- (IBAction)UploadButton:(id)sender
{
// Initializtion of some elements
UIAlertView *alertWait;
alertWait = [[UIAlertView alloc] initWithTitle:@"Please Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alertWait show];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//Web service call statements
dispatch_async(dispatch_get_main_queue(), ^{
//Do your UI operations here
if ([status intValue] == 0)
{
NSLog(@"It is zero");
[alertWait dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert =[ [UIAlertView alloc]initWithTitle:@"Success" message:@"You have
successfully uploded the document and waiting for approval" delegate:self
cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
});
});
}
这篇关于警报视图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!