0

I use a ASINetWorkQueue in a ViewController. So, during the queue is performing, i want to show a MBProgressHUD.

- (void) addItemsToEndOfTableView{
NSLog(@"add items");
[[self networkQueue] cancelAllOperations];

// Création d'une nouvelle file (queue) de requetes
[self setNetworkQueue:[ASINetworkQueue queue]];
[[self networkQueue] setDelegate:self];
[[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)];
[[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)];
[[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)];

...add requests

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.dimBackground = YES;
HUD.delegate = self;

[HUD showWhileExecuting:@selector(stopHub) onTarget:self withObject:nil animated:YES];
}
[[self networkQueue] go];

so, when queueFinished is call, i want to stop the hud:

- (void)queueFinished:(ASINetworkQueue *)queue
{
    [self stophud];
}

-(void)stophud
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

but actually, the progress Hud disappear quickly, whereas activity indicator in the top bar of iphone is running while data being collect.

So, what's wrong ?

Astram56
  • 536
  • 1
  • 7
  • 17
  • Are you sure you don't have other reuest running out of queue? – Marco Pace Jun 12 '12 at 12:13
  • yes, all my request are in the queue by [[self networkQueue] addOperation:request] and each one have a tag – Astram56 Jun 12 '12 at 12:21
  • so, finally i use another library : https://github.com/samvermette/SVProgressHUD and it works great... and its so easy to make it working.. – Astram56 Jun 12 '12 at 12:32
  • I don't think it will be the solution: you have a problem with the network, SVProgress and MBprogress are related with a custom view. – Marco Pace Jun 12 '12 at 12:33
  • yes they are related, but one is working like i want, not the other, so i don't say my code is perfect, but it is better now with SVProgressHUD. The reason... i don't know – Astram56 Jun 12 '12 at 12:46
  • Hope it will work, but in IT "i don't know" is never a good answer for an implementation :). – Marco Pace Jun 12 '12 at 12:48

1 Answers1

0

From MBprogressHUD API

/** 
 * Shows the HUD while a background task is executing in a new thread, then hides the HUD.
 *
 * This method also takes care of autorelease pools so your method does not have to be concerned with setting up a
 * pool.
 *
 * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread.
 * @param target The object that the target method belongs to.
 * @param object An optional object to be passed to the method.
 * @param animated If set to YES the HUD will (dis)appear using the current animationType. If set to NO the HUD will not use
 * animations while (dis)appearing.
 */
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated;

Since you are using this method, your stophud is executed in a new thread. This could cause the strange problem you have (I suppose).

Insetad of using it, try to use

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// set the properties here...

to show it after starting the queue and

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

to hide it when the queue has finished.

Hope it helps.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190