我想在后台创建图片加载并让内容首先加载。我尝试了下面的代码,但没有工作。哪里不对?帮我。
预先感谢您。如何快速加载内容在后台加载内容?
- (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];
}
}
添加请使用图片加载页面。 – Avt
你的问题不清楚。首先获取所有图像的内容(您需要的)和网址,显示所有内容,然后开始在后台下载所有图像 –
@DineshKaushik:谢谢。它确实工作 –