我正在开发一个 iOS 应用程序。我有一个包含一些图像的 Collection View 。图像来 self 创建的数组。当我单击 Collection View 的单元格时,会打开第二个 View Controller 。我想显示我在第二个 View Controller 上单击了 Collection View 的特定图像。如何做到这一点?
最佳答案
在 SecondViewController 中创建图像对象,如下所示:
@property (nonatomic, strong) UIImageView *detailImageView;
@property (nonatomic, strong) UIImage *detailImage;
在您的 FirstViewController.m 中执行以下操作:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionViewObject dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.detailImage = cell.imageView.image;
[self.navigationController pushViewController:secondViewController animated:YES];
}
然后在SecondViewController.m中的viewDidLoad方法
- (void)viewDidLoad
{
[super viewDidLoad];
self.detailImageView.image = self.detailImage;
}
希望这对你有用!!
关于ios - 如何在单击 Collection View 上的单元格时在详细 View 上获得相同的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30236195/