ios - 警报 View 不工作

标签 ios iphone uialertview

我有一个按钮,该按钮向网络服务发送调用并返回一些值。我想显示一个没有按钮的警告框,直到值从 web 服务返回。但是 alertWait 在收到值后显示。我尝试使用设置警报功能并从按钮的开头调用,但它也显示在接收值的末尾。我哪里出错了这是我的代码。

    - (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];
        }

   }

最佳答案

将服务调用放在后台线程上,就像下面更改的示例代码一样:

- (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];
                }
            });
       });

}

关于ios - 警报 View 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23843752/

相关文章:

iphone - 分析时 Instruments.app 崩溃

iphone - 如何避免隐藏导航栏时出现黑框?

ios - UIDatePicker 自定义

ios - 如何在 ios swift 中点击时将警报中的图像显示为更大的图像

ios - NSDictionary 被视为 bool 值 - 无法调试

ios - 保存 Int Array CoreData Swift 3 的最干净方法

iphone - 当 View 移出其 super View 时,touchesBegan 停止工作

ios - 使用 UIAlertView 以编程方式退出 iOS 应用程序

ios - 在 Storyboard中,在将代码提交并推送到 git-bitbucket 后,xib 的导出被 stash

javascript - 如何在页面加载时打开 iOS 键盘