7

我在填充 TableView 时显示 HUD,但它似乎显示在 TableView 后面(打破 hud 的 tableview 分隔符)。

在此处输入图像描述

这是 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;
}

它只对 TableViews 执行此操作。

4

4 回答 4

12

这里的问题是您在视图加载时添加 HUD,这可能在您的 tableView 显示之前,所以 tableView 被创建并似乎覆盖了 HUD。将该代码移动到 viewDidAppear 中,您的问题就会消失:

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

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = @"Loading";
}
于 2014-08-29T22:04:24.660 回答
12

如果您self.navigationController.viewself.viewviewDidLoad

于 2014-11-13T04:26:34.270 回答
10

包括这个:

#import <QuartzCore/QuartzCore.h>

您可以使用layer.zPosition来订购对象/视图的可见性。

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

zPosition 值越高,显示的优先级越高。

于 2015-02-03T07:59:30.553 回答
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];

     });
  });

}

于 2015-12-08T09:27:05.357 回答