title: Failed to load image in a UICollectionView
body: <p>I need to show flickr public images in a <code>UICollectionView</code>. I have done all the things, but images don't load in the <code>UICollectionView</code>. I am new to objective-c. Please help.</p>
  
  <pre><code>   authorIds = [[NSMutableArray alloc] init];
      dateTaken = [[NSMutableArray alloc] init];
      smallImageUrlArray = [[NSMutableArray alloc] init];
      largeImageUrlArray = [[NSMutableArray alloc] init];
      smallImageArray = [[NSMutableArray alloc] init];
  
      UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
      layout.minimumLineSpacing = 10;
      layout.minimumInteritemSpacing = 10;
      layout.sectionInset = UIEdgeInsetsMake(110, 20, 20, 20);
      _collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
      [_collectionView setDataSource:self];
      [_collectionView setDelegate:self];
      [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
      [_collectionView setBackgroundColor:[UIColor blackColor]];
      [self.view addSubview:_collectionView];
  
  
  
      - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
      {
        return totalImageNo;
      }
  
  
      - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView  cellForItemAtIndexPath:(NSIndexPath *)indexPath
     {
      UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
  
      UIImageView *cellImageView = (UIImageView *)[cell viewWithTag:100];
  
      cellImageView.image = [UIImage imageNamed:[smallImageUrlArray objectAtIndex:indexPath.row]];
      //[self.view addSubview:cellImageView];
      [cell.backgroundView addSubview:cellImageView];
  
  
  
  
  
     // NSLog(@"%@",[smallImageUrlArray objectAtIndex:indexPath.row]); //Here can show Img's values correctly
  
      cell.backgroundColor=[UIColor darkGrayColor];
      return cell;
  }
  
      - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
      {
        return CGSizeMake(160, 160);
      }
  </code></pre>
  
  <p>In below I am fetching Flickr images and storing in array. then want to load the smallImageArray in the UICollection view. but nothing shows up.    </p>
  
  <pre><code>-(void)fetchFlickrPublicImages
      {
          NSString *urlString = [NSString stringWithFormat:@"http://api.flickr.com/services/feeds/photos_public.gne?format=json&amp;tags=data"];
  
          NSURL *url = [NSURL URLWithString:urlString];
  
          NSData *badJSON = [NSData dataWithContentsOfURL:url];
  
          NSString *dataAsString = [NSString stringWithUTF8String:[badJSON bytes]];
  
          NSString *correctedJSONString = [NSString stringWithString:[dataAsString substringWithRange:NSMakeRange (15, dataAsString.length-15-1)]];
          correctedJSONString = [correctedJSONString stringByReplacingOccurrencesOfString:@"\\'" withString:@"'"];
  
          NSData *correctedData = [correctedJSONString dataUsingEncoding:NSUTF8StringEncoding];
  
          NSError* error;
          NSDictionary *json = [NSJSONSerialization JSONObjectWithData:correctedData options:kNilOptions error:&amp;error];
  
          NSArray *images = [json objectForKey:@"items"];
  
          for (NSDictionary *image in images)
          {
              NSString *authorId = [image objectForKey:@"author_id"];
  
              [authorIds addObject:(authorId.length &gt; 0 ? authorId: @"Untitled")];
  
              NSString *largeImageUrl = [NSString stringWithFormat:@"%@",[[image objectForKey:@"media"] objectForKey:@"m"]];
  
              NSString *smallImageUrl = [largeImageUrl stringByReplacingOccurrencesOfString:@"_m" withString:@"_s"];
  
              [smallImageUrlArray addObject:smallImageUrl];
  
              [dateTaken addObject:[NSString stringWithFormat:@"%@",[image objectForKey:@"date_taken"]]];
  
              [largeImageUrlArray addObject:[NSString stringWithFormat:@"%@",[[image objectForKey:@"media"] objectForKey:@"m"]]];
  
              totalImageNo = authorIds.count;
          }
  
  
          for (int i=0; i&lt; smallImageUrlArray.count; i++) {
  
              UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                                                          [NSURL URLWithString:[smallImageUrlArray objectAtIndex:i]]]];
  
              [smallImageArray addObject:image];
          }
          NSLog(@"%@", smallImageArray);
  
          NSLog(@"%ld", (long)totalImageNo);
         // NSLog(@"authorIds: %@\n\n", authorIds);
         // NSLog(@"photoURLsLareImage: %@\n\n", smallImageUrlArray);
         // NSLog(@"photoURLsLareImage: %@\n\n", largeImageUrlArray);
  
      }
  </code></pre>