2014-03-01 108 views
-1

我想在后台创建图片加载并让内容首先加载。我尝试了下面的代码,但没有工作。哪里不对?帮我。
预先感谢您。如何快速加载内容在后台加载内容?

- (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]; 
    } 
} 
+0

添加请使用图片加载页面。 – Avt

+0

你的问题不清楚。首先获取所有图像的内容(您需要的)和网址,显示所有内容,然后开始在后台下载所有图像 –

+0

@DineshKaushik:谢谢。它确实工作 –

回答

0

请使用AFNetworking下载的内容,还下载图像的背景下,AFNetworking自带的UIImageView类这将是非常有益的。

1

第一获取所有图像的内容(您需要)和网址,显示所有内容,然后开始下载所有图像的背景。