MBProgressHUD and UITableView

会有一股神秘感。 提交于 2020-01-03 09:07:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!