MBProgressHUD is not showing sometime in iOS
ios, json, mbprogresshud
Solution
Switch your code to this:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_queue_t myqueue = dispatch_queue_create("queue", NULL);
dispatch_async(myqueue, ^{
//Whatever is happening in the fetchedData method will now happen in the background
[self fetchedData:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tbl reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
You don't want to call the `fetchData` method on the main thread. If you use the code above, nothing in the `fetchedData` method will happen on the main thread, so make sure you don't update the UI or anything in there.
Just a suggestion, I wouldn't use the name `"queue"` for your `dispatch_queue`. The names of the queues across the app need to be unique, so I'd call it something like `"your.bundle.id.viewcontrollername"` just to avoid issues later.
Problem
I am using `MBProgressHUD` Custom Control to show when loading JSON Data from web. I have already find a lot of answer that doesn't show correctly HUD Control in their View. Here is my code to show `HUD` in my View. ``` [MBProgressHUD showHUDAddedTo:self.view animated:YES]; ``` and Here is how i hide my `HUD` View. ``` [MBProgressHUD hideHUDForView:self.view animated:YES]; ``` In ViewDidLoad , that control is working fine. But when i click to refresh button and want to show HUD control , it doesn't show HUD Control. ``` [MBProgressHUD showHUDAddedTo:self.view animated:YES]; dispatch_queue_t myqueue = dispatch_queue_create("queue", NULL); dispatch_async(myqueue, ^{ [self performSelectorOnMainThread:@selector(fetchedData:) withObject:nil waitUntilDone:YES]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tbl reloadData]; [MBProgressHUD hideHUDForView:self.view animated:YES]; }); }); ``` I don't know what am I doing wrong? Please help me.