Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 901
Nicolas Rodríguez Seara Avatar asked Aug 29 '14 21:08

Nicolas Rodríguez Seara


2 Answers

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";
}
like image 129
Mike Avatar answered Sep 22 '22 16:09

Mike


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

like image 32
qzhang Avatar answered Sep 19 '22 16:09

qzhang