Ios MBProgressHUD和UITableView
我在填充TableView时显示了一个HUD,但它似乎显示在TableView后面(TableView分隔符破坏了HUD) 以下是TableViewController中的代码:Ios MBProgressHUD和UITableView,ios,uitableview,mbprogresshud,hud,Ios,Uitableview,Mbprogresshud,Hud,我在填充TableView时显示了一个HUD,但它似乎显示在TableView后面(TableView分隔符破坏了HUD) 以下是TableViewController中的代码: - (void)viewDidLoad { [super viewDidLoad]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeText; hud.l
- (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;
}
它仅在tableView中执行此操作。这里的问题是,在加载视图时添加HUD,这可能是在显示tableView之前,因此创建tableView并显示为覆盖HUD。将该代码移动到ViewDidDisplay中,您的问题就会消失:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Loading";
}
如果要在
viewdiload
中实现,请使用self.navigationController.view
而不是self.view
,包括:
#import <QuartzCore/QuartzCore.h>
zPosition值越高,显示优先级越高
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];
});
});
}这应该是公认的答案!而
MBProgressHUD
的演示也使用了这个
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];
});
});