如何快速加载内容加载在后台的图像?

我想要在后台进行图片加载,并让内容首先加载。 我试过下面的代码,但没有工作。 哪里不对? 帮我。
先谢谢你。

- (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,显示所有内容,然后开始下载所有图像的背景。

请使用AFNetworking下载内容,也要在后台下载图像,AFNetworking带有UIImageView类别,这将是非常有用的。

下面的代码是一个完整的可下载示例的一部分,它展示了如何搭build一个UITableView,在后台下载相关图像,并在到达时将它们添加到表格中:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch24p842downloader/ch37p1099downloader/MyTableViewController.m