Reputation: 3604
I am currently displaying an MBProgressHUD
animation while a UITableView
is loading.
I basically create the HUD in viewDidLoad
, and then I trigger a selector which contains all of the UITableView
code.
self.HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
self.HUD.mode = MBProgressHUDAnimationFade;
self.HUD.labelText = @"Finding Friends";
[self performSelector:@selector(myTask) withObject:nil afterDelay:0.001];
I am doing this because my table view blocks the main thread. So basically this allows me to create the HUD before the table view starts and blocks the main thread. That way the HUD is actually visible during the entire table view setup.
I got the above code from this stackoverflow post made by the creator of MBProgressHUD here: Run MBProgressHUD in another thread?
However, now I would like to be able to show the actual progress of the table view being setup using the HUD, but I am confused on how to do this. Right now I just display a "spinning" animation but it doesn't actually show real progress. It just spins.
I would like to use an animation like this: http://dl.dropboxusercontent.com/u/378729/MBProgressHUD/4.png
And then have it fill as the table view code runs.
I am open to any suggestions and thanks for the help.
Upvotes: 0
Views: 445
Reputation: 1258
Try this:
Add this code snippet in your viewDidLoad method. While executing the block set the delegates for tableView so that you can load the data on table views
MBProgressHUD *progressView = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:progressView];
progressView.labelText = kLoadingMessage;
[progressView showAnimated:YES whileExecutingBlock:^
{
self.tableView.datasource = self;
self.tableView.delegate = self;
}
completionBlock:^
{
[progressView removeFromSuperview];
}];
Upvotes: 0