1

I was wondering if it is possible in general to load images via an URL which is parsed via JSON into an UIImageView in a tableview.

I tried this with no success in the UI and only two images in the log. I don't understand why he is showing me only 2 urls instead of 18.

   NSString *bildurl = [[arrayArtikelBild objectAtIndex:indexPath.row] objectForKey:@"bild"];
   NSLog(@"BildURL: %@", bildurl);
   UIImage *image = [UIImage imageWithContentsOfFile:bildurl];
   cell.artikelImage.image = image;

I know that my parsing code work because I let it parse and display other things already (I use NSJSONSerialization).

Thanks in advance.

0

2 Answers 2

1

You could theoretically use:

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:bildurl]]];

but it's highly inadvisable since all the downloads will be done on the main thread + there's no caching. You need to load images asynchronous to achieve smooth scrolling. I'd recommend using https://github.com/rs/SDWebImage or AFNetworking's UIImageView extension (https://github.com/AFNetworking/AFNetworking)

Sign up to request clarification or add additional context in comments.

1 Comment

yeah I just had the same solution and the performance is crap....will check it out thanks
0

You can Using GCD (Grand Central Dispatch) for load image asynchronous

Using this will increase the performance of loading tableview definitely.

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

    dispatch_async(queue, ^{
       UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:bildurl]]];

        dispatch_sync(dispatch_get_main_queue(), ^{
            [cell.artikelImage setImage:image];
            [cell setNeedsLayout];
        });
    });

1 Comment

I would avoid using this exact solution because the URL will not be associated to indexPaths and therefore confuse time images on fast scrolling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.