0

MBProgressHUD が成功/失敗したリクエストのチェックマーク/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 が 1 秒間点滅します。これはスレッド化の問題のようですが、どこでスローされているのかわかりません。

4

1 に答える 1

0

コールバックを作成するコードの部分では、必ずメイン キューでもコールバックを実行してください。

于 2013-10-31T22:51:13.750 に答える