0

我在 ViewController 中使用 ASINetWorkQueue。所以,在队列执行期间,我想显示一个 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];

所以,当 queueFinished 被调用时,我想停止 hud:

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

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

但实际上,进度 Hud 很快消失了,而 iphone 顶部栏中的活动指示器在收集数据时正在运行。

那么,怎么了?

4

1 回答 1

0

来自MBprogressHUDAPI

/** 
 * 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;

由于您使用的是此方法,因此您stophud将在新线程中执行。这可能会导致您遇到的奇怪问题(我想)。

Insetad 使用它,尝试使用

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

在启动队列后显示它和

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

当队列完成时隐藏它。

希望能帮助到你。

于 2012-06-12T12:43:26.227 回答