首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASINetworkQueue和MBProgressHUD

ASINetworkQueue和MBProgressHUD
EN

Stack Overflow用户
提问于 2012-06-12 20:09:45
回答 1查看 364关注 0票数 0

我在ViewController中使用ASINetWorkQueue。因此,在队列执行期间,我想显示一个MBProgressHUD。

代码语言:javascript
复制
- (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:

代码语言:javascript
复制
- (void)queueFinished:(ASINetworkQueue *)queue
{
    [self stophud];
}

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

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

那么,出什么问题了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-12 20:43:26

来自MBprogressHUD API

代码语言:javascript
复制
/** 
 * 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,尝试使用

代码语言:javascript
复制
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// set the properties here...

在启动队列后显示它,并

代码语言:javascript
复制
[MBProgressHUD hideHUDForView:self.view animated:YES];

在队列结束时将其隐藏。

希望能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10996371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档