问题
I am displaying a HUD while populating the TableView, but it seems to be showing behind the TableView (tableview separator breaking the hud).
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.
回答1:
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";
}
回答2:
Use self.navigationController.view
instead of self.view
if you want to implement in viewDidLoad
回答3:
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.
回答4:
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];
});
});
}
来源:https://stackoverflow.com/questions/25576530/mbprogresshud-and-uitableview