title: Why the same images are repeated in all the collection views of iphone sdk
body: <p>I have a table view where am listing some set of images from the XML file which is retrieved as URL. I extended this with Collection Views where when user selects the image in table view corresponding image will take to next window displaying some set of images as collection view. </p>
  
  <p>Here i face a problem as when i click any image in table view it displays the same images for all collection views. For better understanding i attached the image below, </p>
  
  <p><img src="https://i.stack.imgur.com/wOknt.png" alt="Collection Images"></p>
  
  <p>In this, the table view shows Image-1,Image-2... and so on. When i click the Image-1 in table view the collection view displays as Image1-1,Image1-2,.. and so on. Again when i click the Image-2 in table view it again shows the same Image-1-1, Image-1-2 ...and so on. </p>
  
  <p>Can anyone tell me how to solve this problem,</p>
  
  <p>The corresponding code are shown below,</p>
  
  <p><strong>The tableView</strong></p>
  
  <pre><code>- (void)viewDidLoad
     {
       [super viewDidLoad];
       xmlParser = [[myXMLParser alloc] loadXMLByURL:@"http://sample.com/Images.xml"];
       [self.tableView reloadData];
     }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
     {
       return 1;
     }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     {
       return [xmlParser.tweets count];
     }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
      static NSString *CellIdentifier = @"images";
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }
      UIImage *currentTweet = [[xmlParser tweets] objectAtIndex:indexPath.row];
      UIImageView *tweetImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,cell.frame.size.width , cell.frame.size.height)];
      tweetImageView.image = currentTweet;
      [cell setBackgroundView:tweetImageView];
      return cell;
    }
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
    MyCollectionViewController *collectViewController = [[MyCollectionViewController alloc] initWithNibName:@"detail" bundle:nil];
    [self.navigationController pushViewController:collectViewController animated:YES];
  }
  </code></pre>
  
  <p><strong>The CollectionView</strong></p>
  
  <pre><code>- (void)viewDidLoad
      {
        [super viewDidLoad];
        xmlParser = [[myXMLParser alloc] loadXMLByURL:@"http://sample.com/Images.xml"];
        UIImage *currentImage = [[xmlParser tweets] objectAtIndex:0];
        customimage.image = currentImage;
        UIImage *currentImage1 = [[xmlParser tweets] objectAtIndex:1];
        customimage1.image = currentImage1;
      }
  
  -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
     {
       return 1;
     }
  
  -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
      return [xmlParser.tweets count];
    }
  
  -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
      MyCollectionViewCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
      UIImage *currentTweet = [[xmlParser tweets] objectAtIndex:indexPath.row];
      UIImageView *tweetImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,myCell.frame.size.width , myCell.frame.size.height)]; 
      tweetImageView.image = currentTweet;
      [myCell setBackgroundView:tweetImageView];
      return myCell;
   }
  </code></pre>
  
  <p><strong>UPDATED</strong></p>
  
  <p><strong>MY XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Products&gt;
  &lt;products id="0"&gt;
   &lt;img&gt;http://myimage.com/images/logo1.png&lt;/img&gt;
  &lt;/products&gt;
   &lt;products id="1"&gt;
   &lt;img&gt;http://myimage.com/images/Main_pic.png&lt;/img&gt;
  &lt;/products&gt;
  &lt;products id="2"&gt;
  &lt;img&gt;http://myimage.com/images/image1.png&lt;/img&gt;
  &lt;/products&gt;
  &lt;products id="3"&gt;
  &lt;img&gt;http://myimage.com/images/image2.png&lt;/img&gt;
  &lt;img-subproduct&gt;http://myimage.com/images/image2-1.png&lt;/img-subproduct&gt;
  &lt;img-subproduct&gt;http://myimage.com/images/image2-2.png&lt;/img-subproduct&gt;
  &lt;/products&gt;
  &lt;products id="4"&gt;
  &lt;img&gt;http://myimage.com/images/image3.png&lt;/img&gt;
  &lt;img-subproduct&gt;http://myimage.com/images/image3-1.png&lt;/img-subproduct&gt;
  &lt;img-subproduct&gt;http://myimage.com/images/image3-2.png&lt;/img-subproduct&gt;
  &lt;/products&gt;
  &lt;/Products&gt;
  </code></pre>