我有一个表格视图,其中列出了作为 URL 检索的 XML 文件中的一组图像。我用集合视图扩展了它,当用户在表格视图中选择图像时,相应的图像将进入下一个窗口,将一组图像显示为集合视图。
在这里我面临一个问题,因为当我单击表格视图中的任何图像时,它会为所有集合视图显示相同的图像。为了更好地理解,我附上了下面的图片,

在此,表格视图显示 Image-1、Image-2... 等等。当我单击表视图中的 Image-1 时,集合视图显示为 Image1-1、Image1-2、.. 等等。当我再次单击表格视图中的 Image-2 时,它再次显示相同的 Image-1-1、Image-1-2 ...等等。
谁能告诉我如何解决这个问题,
对应的代码如下所示,
表视图
- (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];
}
集合视图
- (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;
 }
更新
我的 XML
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<products id="0">
 <img>http://myimage.com/images/logo1.png</img>
</products>
 <products id="1">
 <img>http://myimage.com/images/Main_pic.png</img>
</products>
<products id="2">
<img>http://myimage.com/images/image1.png</img>
</products>
<products id="3">
<img>http://myimage.com/images/image2.png</img>
<img-subproduct>http://myimage.com/images/image2-1.png</img-subproduct>
<img-subproduct>http://myimage.com/images/image2-2.png</img-subproduct>
</products>
<products id="4">
<img>http://myimage.com/images/image3.png</img>
<img-subproduct>http://myimage.com/images/image3-1.png</img-subproduct>
<img-subproduct>http://myimage.com/images/image3-2.png</img-subproduct>
</products>
</Products>