如何在后台加载图像时快速加载内容? [英] How to load content fast with images loading in background?
本文介绍了如何在后台加载图像时快速加载内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在后台加载图像,然后先加载内容.我尝试下面的代码,但没有工作.怎么了?帮帮我
预先谢谢你.
I want to make image load in background and let content load first. I tried below code but didnt work. What is wrong? Help me.
Thank you in advance.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"site.com/json.php"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
self.recipes = [[NSMutableArray alloc] init];
for(NSDictionary *dic in res){
Recipe *recipe = [[Recipe alloc] init];
recipe.name = [dic objectForKey:@"title"];
recipe.imageName = [NSString stringWithFormat:@"site.com/iphone_images/%@",[dic objectForKey:@"imageName"]];
[recipes addObject:recipe];
[myTableView reloadData];
}
}
推荐答案
首先获取所有图像的内容(所需)和url,显示所有内容,然后开始在后台下载所有图像.
First get content (which you need) and url of all the images , show all the content and then start downloading of all image in background.
这篇关于如何在后台加载图像时快速加载内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文