Objective c 带tableview的MBProgresshud
我正在制作一个包含tableview的应用程序。我想实现一个加载屏幕,使用MBProgressHUD,以便在从internet读取数据之前显示。但是,数据未使用以下代码显示:Objective c 带tableview的MBProgresshud,objective-c,mbprogresshud,Objective C,Mbprogresshud,我正在制作一个包含tableview的应用程序。我想实现一个加载屏幕,使用MBProgressHUD,以便在从internet读取数据之前显示。但是,数据未使用以下代码显示: - (void)viewDidLoad { HUD = [[MBProgressHUDalloc] initWithView:self.view]; [self.viewaddSubview:HUD]; HUD.delegate = self; [HUD showWhileExecuting:@selector(
- (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(即[自加载数据])在tableview中显示,但不能与HUD一起显示。根据我的经验,在加载或等待加载数据时使用HUD显示时,应在-VIEWDIDDEAMENT方法中调用HUD。我还注意到您没有包括[super viewDidLoad];调用你的代码。如果要显示HUD,如果希望它显示,则必须在调用super viewDidLoad后调用它。希望这些方法能帮助您。我喜欢使用单独的方法来显示和隐藏HUD,这些方法只能做到这一点。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可以独立于视图生命周期以及异步方法、计时器等进行控制。例如:
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showHudWithText:) name:kSomethingImportantStartedNotification object:@"Starting..."];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideHud) name:kSomethingImportantEndedNotification object:nil];
}
或者类似的