-1

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];
   }
}
Santosh
  • 363
  • 2
  • 14
  • Add please your image loading code. – Avt Mar 01 '14 at 17:50
  • Your question is not clear. First get content (which you need) and url of all the images , show all the content and then start downloading of all image in the background – Dinesh Kaushik Mar 01 '14 at 17:53
  • I think your solution is not working because you are lack of essential knowledge about working with multiple threads. first you should read this: https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html, if you are still stuck, present your solution for discussion. – holex Mar 01 '14 at 19:11
  • @holex, i will go through it. The way i have done is mentioned bellow. Thank you. – Santosh Mar 02 '14 at 05:15

3 Answers3

1

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.

Dinesh Kaushik
  • 2,917
  • 2
  • 23
  • 36
0

Please use AFNetworking to download the contents,also to download the images in the background ,AFNetworking comes with the UIImageView category which would be very much helpful.

Nassif
  • 1,113
  • 2
  • 14
  • 34
0

Here's code that is part of a complete downloadable example showing how to put up a UITableView, download the related images in the background, and add them to the table when they arrive:

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

matt
  • 515,959
  • 87
  • 875
  • 1,141