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];
}
the data can be shown in tableview using the function load_data alone (i.e [self load_data], but not with HUD.
I like to present and hide the HUD with separate methods that only do that. e.g.
This allows the HUD to be controlled independently of the view life cycle, as well as from asynchronous methods, timers, etc. e.g:
Or something like that.
In my experience, when using the HUD to display while loading or waiting for data to load, you should call the HUD in the
-viewDidAppear
method. I also noticed that you didn't include the [super viewDidLoad]; call in your code. If you are going to present your HUD, you will have to call it after you call on the super viewDidLoad if you want it to appear. Hopefully these help you out.