How to add MBProgressHUD waiting loading data in iOS

Joson Daniel picture Joson Daniel · Oct 14, 2013 · Viewed 15.1k times · Source

I have a problem: I used AFNetworking to get data from server, i used NSOperationQueue to add many operation to it, in each request, I added this operation to queue and used waitUntilAllOperationsAreFinished as bellow :

request 1
...
    [queue addOperation:operation1];
    [queue waitUntilAllOperationsAreFinished];

request 2
...
    [queue addOperation:operation2];
    [queue waitUntilAllOperationsAreFinished];

I tried above code and my programs seems hangs and after that, it runs ok.So that I want to added MBProgressHUD to waiting queue finish, then I want to check if queue finish, I want to hide MBProgressHUD. But when i click on Button to load UIViewController, MBProgressHUD cannot show.

HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";

Actually, I want to show MBProgressHUD when queue finish. How can i do that? Thanks all

Answer

sunkehappy picture sunkehappy · Oct 14, 2013

Shortly you can do it like this:

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];

Check MBProgressHUD's usage