我正在解决这个问题,MBProgressHUD应该使用Checkmark / X更新其View以查找成功/失败的请求。不知何故,这并没有真正按预期工作,只有在所有代码执行完毕后才能使用更新。
...
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 - 更新的一个闪烁了一秒钟。 看起来,这是一个线程问题 - 但我似乎无法弄清楚它在哪里抛出。
答案 0 :(得分:0)
在您进行回调的代码部分中,请务必同时在主队列上执行回调。