title: UICollection view cells wrong redrawing
body: <p>I have issue with redrawing images of uicollectionview cells - images are downloaded from URL parsed from JSON. I have 10 cells and with the start of app only first 6 are displayed, but images are not loaded, when I scroll down to those other cells, they have their images, and when I scroll back to the top, first 4 cells have their images as well, only cells 5 and 6 are not redrawn(they were visible for the whole time). I've been trying to debug this for long time but no success. </p>
  
  <p>in cellForItemAtIndexPath I'm calling SDWebImage(but it doesn't really matter):</p>
  
  <pre><code>[cell.backgroundImage setImageWithURL:[NSURL URLWithString:timeSnap.thumbnailImageURL]  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  </code></pre>
  
  <p>but when cellForItemAtIndexPath is called for the first time, timeSnap.thumbnailImageURL(where timeSnap entity is model for cell) is not initialised yet and so it's null</p>
  
  <p>after initialisation of timeSnap.thumbnailImageURL I have:</p>
  
  <pre><code>dispatch_async(dispatch_get_main_queue(), ^{
      [self.collectionView reloadData];
  });
  </code></pre>
  
  <p><strong>edit1:</strong>
  adding my code, it's a bit complex - first I'll get JSON from server API with items to be displayed in collection view, then for each item I have to get another JSON from server API, from which I can build URL for timeSnap.thumbnailImageURL</p>
  
  <p><strong>viewController class:</strong></p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      [self refreshNewTimeSnapsFeed];
  }
  
  - (void)refreshNewTimeSnapsFeed {
      Adapter *adapter = [AppDelegate instance].adapter;
  
      [adapter getNewTimeSnapsWithCompletion:^(NSArray* jsonResponse) {
          [self newTimeSnapsFeedRefreshed:jsonResponse];
      }];
  }
  
  - (void)newTimeSnapsFeedRefreshed:(NSArray*)jsonResponse {
  Adapter *adapter = [AppDelegate instance].adapter;
  
      for (NSDictionary *timeSnapDict in jsonResponse) {
          TimeSnap *timeSnap = [[TimeSnap alloc] initWithJSON:timeSnapDict];
          [adapter getTimeSnapSnapsforId:timeSnap.id withCompletion:^(NSArray*     jsonResponse) {
              [timeSnap getSnapsJSON:jsonResponse];
              [timeSnap getTimeSnapThumbnailImageURL];
          }];
  
          [self.timeSnaps addObject:timeSnap];
      }
  
      dispatch_async(dispatch_get_main_queue(), ^{
          [self.collectionView reloadData];
      });
  }
  
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  
      TimeSnapCell *cell = (TimeSnapCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"TimeSnapCell" forIndexPath:indexPath];
  
      TimeSnap *timeSnap = self.timeSnaps[indexPath.row];
  
      cell.label.text = timeSnap.name;
  
      [cell.backgroundImage setImageWithURL:[NSURL URLWithString:timeSnap.thumbnailImageURL]  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  
      return cell;
  }
  </code></pre>
  
  <p>adapter class:</p>
  
  <pre><code>- (void)getNewTimeSnapsWithCompletion:(void (^)(NSArray* jsonResponse))completion {
  
      NSString *urlAsString = [NSString stringWithFormat:@"..."];
      NSURL *url = [[NSURL alloc] initWithString:urlAsString];
  
      [self getJSONWithCompletion:completion fromURL:url forKey:@"Items"];    
  }
  
  - (void)getTimeSnapSnapsforId:(NSNumber*)id withCompletion:(void (^)(NSArray* jsonResponse))completion {
  
      NSString *urlAsString = [NSString stringWithFormat:@"..."];
      NSURL *url = [[NSURL alloc] initWithString:urlAsString];
  
      [self getJSONWithCompletion:completion fromURL:url forKey:@"Items"];    
  }
  
  - (void)getJSONWithCompletion:(void (^)(NSArray* jsonResponse))completion fromURL:(NSURL*)url forKey:(NSString*)key {
  
      //code for getting JSON from server API, then parsing into NSArray *items
  
      dispatch_async(dispatch_get_main_queue(), ^{
          if(completion){
              completion(items);
          }
      });    
  }
  </code></pre>