gpt4 book ai didi

ios - 如何在单击 Collection View 上的单元格时在详细 View 上获得相同的图像?

转载 作者:行者123 更新时间:2023-11-29 02:02:04 26 4
gpt4 key购买 nike

我正在开发一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com