【问题标题】:MBProgressHUD and UITableViewMBProgressHUD 和 UITableView
【发布时间】:2014-10-23 22:51:51
【问题描述】:

我在填充 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 执行此操作。

【问题讨论】:

    标签: ios uitableview mbprogresshud hud


    【解决方案1】:

    这里的问题是您在视图加载时添加 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";
    }
    

    【讨论】:

      【解决方案2】:

      如果您想在viewDidLoad 中实现,请使用self.navigationController.view 而不是self.view

      【讨论】:

        【解决方案3】:

        包括这个:

        #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 值越高,显示的优先级越高。

        【讨论】:

        • 这应该是公认的答案!和MBProgressHUD的demo也用这个
        【解决方案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];
        
             });
          });
        

        }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-28
          • 2012-04-01
          • 1970-01-01
          相关资源
          最近更新 更多