iosuitableviewmbprogresshudhud

MBProgressHUD and UITableView


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.


Solution

  • 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";
    }