我有一个典型的“向下钻取”风格的应用程序,它有一个包含UIImageView、UIWebView和几个UILabel的DetailViewController,问题是imageView需要更长的时间才能加载!它会变成白色(背景色)一段时间,然后在3-5秒后最终加载(可能是下载所需的时间)。
代码是:
- (void)loadSummary {
self.dogFood = [[IKFetcher sharedFetcher] fetchDogFoodInfoForId:self.dogFoodId];
self.dogFoodAnalysisArray = [[IKFetcher sharedFetcher] fetchDogFoodAnalysisArrayForId:self.dogFoodId];
self.dogFoodRating = [[IKFetcher sharedFetcher] getAvgDogFoodRatingForId:self.dogFoodId];
if ([self.dogFood.dfImageUrl length] != 0) {
self.dogFoodImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.dogFood.dfImageUrl]]];
}
}并且对loadSummary的调用被包装在一个dispatch_async调用中。
如何才能让应用程序等待镜像下载?
发布于 2012-01-08 10:06:34
问题是您为dataWithContentsOfURL提供了一个远程URL。下载它需要时间,而且它可能永远不会到达。这很冒险。相反,显示占位符并使用NSURLConnection在背景中下载真实的图像;它将在获得图像时调用代理,现在您可以立即显示它。
发布于 2013-03-25 03:37:52
我建议
SDWebImage,所以你不需要自己去实现它。
https://stackoverflow.com/questions/8774813
复制相似问题