7

I am displaying a HUD while populating the TableView, but it seems to be showing behind the TableView (tableview separator breaking the hud).

enter image description here

Here's the code in the TableViewController:

- (void)viewDidLoad {
[super viewDidLoad];

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Loading";

// Populate the table
[self getTableData];

self.tableView.rowHeight = 90;
}

It's doing this only with TableViews.

Acey
  • 8,048
  • 4
  • 30
  • 46

4 Answers4

12

The issue here is that you are adding the HUD when the view loads, which is likely before your tableView has been displayed, so the tableView is created and appears to cover the HUD. Move that code into viewDidAppear and your problem will go away:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = @"Loading";
}
Mike
  • 9,765
  • 5
  • 34
  • 59
12

Use self.navigationController.view instead of self.view if you want to implement in viewDidLoad

Vivek Pradhan
  • 4,777
  • 3
  • 26
  • 46
qzhang
  • 121
  • 1
  • 3
10

Include this:

#import <QuartzCore/QuartzCore.h>

You can use layer.zPosition to order the visibility of your objects/views.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Loading";
hud.layer.zPosition = 2;
self.tableView.layer.zPosition = 1;

The higher zPosition value, more priority in display.

user3045072
  • 654
  • 9
  • 13
0
Even in ViewDidLoad also we can handle it like this::   
  - (void)viewDidLoad {
 [super viewDidLoad];     
   MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  hud.labelText = @"Loading..";
  dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
   [self contactsFromAddressBook];
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
       [self.tableView reloadData];

     });
  });

}

Mannam Brahmam
  • 2,225
  • 2
  • 24
  • 36