0

I have some problems with MBProgressHUD. I am downloading some images and JSON and trying to show the status.

This is on my viewdidload:

HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.labelText = @"Lade Bilder runter...";
HUD.mode = MBProgressHUDModeAnnularDeterminate;
HUD.detailsLabelText = @"Schritt 1 von 2";
HUD.yOffset = -10;
[self.view addSubview:HUD];
[HUD show:YES];
[self downloadImages];

showWhileExecuting is not working with NSOperationQueue. I have no idea why. So, the method downloadImages uses NSOperationQueue in order to process the download with AFNetworking. After the NSOperationQueue is finished I call finishedDownload.

That method calls

[HUD hide:YES];

This is working. The HUD is hiding but the UITableView is being blocked for about 2seconds. After those 2 seconds the HUD flashes up and hides instantly. After that flash I can interact with the UITableView.

What's the problem here? I really appreciate help.

Thanks

dozed
  • 192
  • 4
  • 12

2 Answers2

0

I would try moving this bit of code to -viewDidAppear: instead of -viewDidLoad:. There are definitely some weird issues when superviews aren't fully situated before subviews perform animations.

Community
  • 1
  • 1
Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
0

I would do as the other answer said and move your logic to viewDidLoad or viewDidAppear to prevent any startup issues for the view.

Also, you need to give the UI thread enough time to show the HUD before starting your network call. Since you obviously need the data before you can do anything in your view, you are on the right path. You just need to allow the HUD time to show and dismiss.

The HUD is typically UI blocking while being shown... so the user isn't going to be able to do anything with the current view (back buttons, other buttons) but will be able to access other things like a tab bar item or anything not linked to the view you added the HUD to.

I would actually change your network call.

Change this:

[self downloadImages];

To this:

[self performSelector:@selector(downloadImages) withObject:nil afterDelay:0.1];

This will free your thread up to complete showing the HUD. Dismissing usually isn't a problem since your actions complete with the HUD closing anyway. But sometimes you can have a similar issue, so you can consider moving your HUD dismiss call to a method that can be called on the main thread. Hope this helps.

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86