Objective c 目标C-UICollectionViewController-使用segues

Objective c 目标C-UICollectionViewController-使用segues,objective-c,uicollectionview,Objective C,Uicollectionview,我迷路了。我有一个UICollectionViewController,它有4个项目,每个项目都有一个imageView和一个image。我想将图像从选定项目传递到视图控制器: - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.item == 0) {

我迷路了。我有一个UICollectionViewController,它有4个项目,每个项目都有一个imageView和一个image。我想将图像从选定项目传递到视图控制器:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  {
      if (indexPath.item == 0)
      {
          [self performSegueWithIdentifier:@"FinalFace" sender:self];
      }
  }

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
       FinalViewController *controller = segue.destinationViewController;
  }

可以将选定的indexPath存储在属性中,也可以使用

[[self.collectionView indexPathsForSelectedItems] firstObject]

以检索所选单元格。拥有单元格后,您可以访问其imageView属性,并将其图像传递给FinalViewController(记住在其上创建公共属性)。

andreamazz:抱歉,我不清楚。如何将图像从集合视图中单击的项目传递到FinalViewController。我不知道如何将单击单元格的indexPath.item放入prepareForSegue方法中,这样我就可以编写:if(indexPath.item==int),后面跟着将数据传递给FinalViewController的语句。andreamazz:非常感谢您的帮助!!我相信这会奏效的。