0

Using any form of progressHUD (SV, MB, etc) I run into this problem where the HUD is either hidden right after it is displayed or stays there permanently. In the below example, the HUD stays permanently, regardless of if the twitter feed (or page for other view controllers) has finished loading. How can I make the HUD disappear after the task in the separate thread completes?

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

       //Sets the auth key (user or app) for the RMACC Twitter Feed
       STTwitterAPI *twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];

       [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

           [twitter getUserTimelineWithScreenName:@"RMACCNewsNotes" count:10 successBlock:^(NSArray *statuses) {

               dispatch_async(dispatch_get_main_queue(), ^{
                   [MBProgressHUD hideHUDForView:self.view animated:YES];
               });

               self.twitterFeed =[NSMutableArray arrayWithArray:statuses];

               [self.tableView reloadData];

            } errorBlock:^(NSError *error){ }];

        } errorBlock:^(NSError *error) {
            [self twitterselfauthrequest];
        }];

    });        
}
Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41
jclark754
  • 914
  • 2
  • 12
  • 30

3 Answers3

1
  1. It is not secure capture self in a block: use: __weak typeof (self) weakSelf = self; out the first block.

  2. You are calling [self.tableView reloadData]; not in the main thread;

  3. This request: getUserTimelineWithScreenName could finish in an error: in that case you have not log so be sure that it finish with success.

Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41
1

It should be something like this:

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

// do all your twitter stuff, including the error checking

      dispatch_async(dispatch_get_main_queue(), ^{
         [self.tableView reloadData];
         [MBProgressHUD hideHUDForView:self.view animated:YES];
      });
});
koen
  • 5,383
  • 7
  • 50
  • 89
0

I've observed two things that could be a problem:

  1. Are you sure that this line is launched in main thread?

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

  2. Are you sure that this line is launched at all?

    [MBProgressHUD hideHUDForView:self.view animated:YES];

Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51