2013-02-19 42 views

回答

0

我不确定SVProgressHUD的实现是什么,但我在当前的应用程序中使用了一个名为MBProgressHUD的类似工具。希望这个建议仍然适用。

如果我正确理解你的问题,你想知道如何解雇你的progressHUD如果AFNetworking调用失败?如果这是你的问题,那么你所需要做的就是在你的失败区中关闭你的HUD,如下所示。

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; 
[navigationController.view addSubview:HUD]; 

HUD.dimBackground = YES; 
[HUD show:YES]; 

//Set up the request 
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"example.com"]]; 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url]; 

[request setHTTPMethod:@"POST"]; 

//Set up the operation 
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

     // Hide activity indicator after success 
     [HUD show:NO]; 
     [HUD hide:YES]; 

} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

    // Hide activity indicator after failure 
    [HUD show:NO]; 
    [HUD hide:YES]; 
}]; 

// Fire off the operation 
[operation start];