我在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顶部栏中的活动指示器正在运行,同时收集数据。
那么,出了什么问题?
答案 0 :(得分:0)
来自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;
由于您使用的是此方法,因此stophud
将在新线程中执行。这可能会导致你遇到的奇怪问题(我想)。
使用它的插入,尝试使用
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// set the properties here...
在启动队列后显示
[MBProgressHUD hideHUDForView:self.view animated:YES];
在队列结束时隐藏它。
希望它有所帮助。