2011-09-05 88 views
0
- (void) didClickDone{ 
    if (isValide ==0) { 
     (...) 
     [newFormDataRequest setDelegate:self]; 
     [newFormDataRequest startAsynchronous]; 
     (...) 
     //show the label 
     [self showWithLabel]; 
    } 
} 




# pragma mark - AsiHTTPRequest delegate methods 
- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"PostAdRequest = %@", [request responseString]); 
    HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease]; 
    HUD.mode = MBProgressHUDModeCustomView; 
    HUD.labelText = @"Completed"; 
    sleep(10); 
    [self hudWasHidden]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 

我想從AsiHTTPRequest獲得積極答案後更改MBPrograssHub。但觀點依然如此。你知道爲什麼嗎 ?MBProgressHUB混合查看

感謝

回答

2

因爲sleep(10)是不允許UIThread更新HUD。

- (void)requestFinished:(ASIHTTPRequest *)request { 
    NSLog(@"PostAdRequest = %@", [request responseString]); 
    HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease]; 
    HUD.mode = MBProgressHUDModeCustomView; 
    HUD.labelText = @"Completed"; 

    [self performSelector:@selector(removeHUD) withObject:nil afterDelay:10.0f]; 
} 

- (void) removeHUD { 
    [self hudWasHidden]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

哎呀!真棒!非常感謝你 –

+0

我甚至不知道你爲什麼在這裏使用sleep():你永遠不應該暫停主線程,並且在大多數操作的輔助線程上使用它並不是所有的原因 - Objective如果你確實需要它,-C就擁有'sleep()'的包裝器。 – lxt

+0

他可能希望該對話框可見,以便告訴用戶它已完成請求。 – rckoenes