带有表视图的MBProgresshud [英] MBProgresshud with tableview
问题描述
我正在制作一个带有表视图的应用程序.我想使用MBProgressHUD实现一个加载屏幕,以便在从Internet读取数据之前显示该屏幕.但是,使用以下代码不会显示数据:
I am making a application with a tableview in it. I would like to implement a loading screen, using MBProgressHUD such that it will display before data is read from internet. However the data's not shown using following code:
- (void)viewDidLoad
{
HUD = [[MBProgressHUDalloc] initWithView:self.view];
[self.viewaddSubview:HUD];
HUD.delegate = self;
[HUD showWhileExecuting:@selector(load_data) onTarget:self withObject:nil animated:YES];
}
可以单独使用load_data函数(即[self load_data],但不能使用HUD在表格视图中显示数据.
the data can be shown in tableview using the function load_data alone (i.e [self load_data], but not with HUD.
推荐答案
我喜欢使用仅能做到这一点的单独方法来呈现和隐藏HUD.例如
I like to present and hide the HUD with separate methods that only do that. e.g.
#pragma mark - The HUD
-(void)showHudWithText:(NSString *)text {
if (self.hud == nil) {
self.hud = [[[MBProgressHUD alloc] initWithWindow:self.window] autorelease];
[self.window addSubview:hud];
}
[self.hud setLabelText:text];
[self.hud setMode:MBProgressHUDModeIndeterminate];
[self.hud show:YES];
}
-(void)hideHud {
[self.hud hide:YES];
}
这允许独立于视图生命周期以及异步方法,计时器等来控制HUD.例如:
This allows the HUD to be controlled independently of the view life cycle, as well as from asynchronous methods, timers, etc. e.g:
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showHudWithText:) name:kSomethingImportantStartedNotification object:@"Starting..."];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideHud) name:kSomethingImportantEndedNotification object:nil];
}
或者类似的东西.
这篇关于带有表视图的MBProgresshud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!