从服务器加载图像时出现MBProgressHUD问题

时间:2011-02-28 10:32:55

标签: iphone objective-c

我有一台服务器,它提供带有某些参数和图像名称的JSON。然后我得到了提供名称的图像。所有这些都在一个名为loadingOfImageAndInformation的函数中完成。我使用MBProgressHUD如下:

    [HUD showWhileExecuting:@selector(loadingOfImageAndInformation) 
                   onTarget:self withObject:nil animated:YES];

当此方法当前正在运行时,哪个应显示进度。现在,在方法内部,我使用ASIHTTPRequest来检索我需要的所有数据。这意味着有时它会从该方法跳转到请求方法(检索图像并将其分配给requestLoadDone上的UIImageView)。

现在,问题是MBProgressHUD东西只显示参数显示(我放在标签上的图像描述,我从JSON获得的描述),直到显示参数AND图像。所以基本上加载器在图像在imageView之前消失。

这是有问题的代码:

- (void) loadingHudAlert {

NSString *loadingMessage = NSLocalizedString(@"Please Wait", 
@"Message displayed when the loading spinner is on");
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.minShowTime = 1.0;
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = loadingMessage;
[HUD showWhileExecuting:@selector(loadingOfImageAndInformation) 
onTarget:self withObject:nil animated:YES];
}

ASIHTTPRequest在异步模式下执行所有请求。没有队列。

感谢您的反馈!!!!

2 个答案:

答案 0 :(得分:1)

我使用布尔值解决了它,如果方法requestLoadDone完成,则bool变为NO,而布尔值为YES则loadOfImageAndInformation将运行(这意味着将运行直到图像被正确检索。)我还没有发布这是一个答案,因为可能有人有更好的解决方案。

答案 1 :(得分:0)

所以你说HUD在你的imageview中显示图像之前消失了,不是吗?也许这更多是由于cocoa如何处理这些东西而不是MBProgressHUD问题。 你是如何分配图像的?你试过吗?

[yourimageview setNeedsDisplay];

我想说的是,如果这是cocoa如何管理显示内容的图像视图,也许你可以尝试“强制”重新加载或显示之前完成。