0

我正在解决这个问题,MBProgressHUD 应该使用 Checkmark/X 更新其视图以获取成功/失败的请求。不知何故,这并没有真正按预期工作,并且更新仅在所有代码执行后才有效。

初始化 HUD

  ...
  MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  hud.labelText = @"Verifying Credit Card";
  _HUD = hud;

  CWAPIClient *client = [CWAPIClient sharedClient];
  client.delegate = self;
  dispatch_queue_t backgroundQueue = dispatch_queue_create("com.clubw.billing", 0);
  dispatch_async(backgroundQueue, ^{
    [client save:billingProfile with:[Address defaultBillingAddress]];
  });
  ....

回调处理信息:

self POST:[NSString stringWithFormat:@"user/%@/billingprofile", [[Profile defaultProfile] userId]] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
      dispatch_async(dispatch_get_main_queue(), ^{
        [self.delegate CWAPIClient:self doneVerifyingCreditCard:responseObject];
      });
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"%@", error);
    }];

动作完成时回调

BOOL success = [[jsonResponse objectForKey:@"success"] boolValue];
  if (success)
  {

    NSLog(@"Thread: %@", [NSThread currentThread]);
    dispatch_async(dispatch_get_main_queue(), ^{

      UIImage *checkmarkImage = [UIImage imageNamed:@"checkmark.png"];
      UIImageView *checkmarkView = [[UIImageView alloc] initWithImage:checkmarkImage];

      _HUD.customView = checkmarkView;
      _HUD.labelText = @"Credit Card Verified!";
      _HUD.mode = MBProgressHUDModeCustomView;
      NSLog(@"Thread: %@", [NSThread currentThread]);

      sleep(5);
      [_HUD hide:YES];
    });

5 秒后,它简单地关闭了 HUD - 更新的 HUD 闪烁一秒钟。看起来,这是一个线程问题 - 但我似乎无法弄清楚它在哪里抛出。

4

1 回答 1

0

在您进行回调的代码部分中,请务必在主队列上执行回调。

于 2013-10-31T22:51:13.750 回答