gpt4 book ai didi

ios - 在 UICollectionViewController 中按下 UICollectionViewCell 后无响应

转载 作者:行者123 更新时间:2023-11-29 12:12:23 25 4
gpt4 key购买 nike

当我将图像从 UICollectionViewController 发送到另一个 ViewController 时,这里是 View A:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Detail Segue"])
{
PhotoDetailViewController *PhotoDetailVC = segue.destinationViewController;
NSIndexPath *path = [[self.collectionView indexPathsForSelectedItems] lastObject];

Photo *selectedPhoto = self.photos[path.row];
PhotoDetailVC.photo = selectedPhoto;
}
}

我在 ViewController( View B)中使用以下方式接收它:

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.imageView.image= self.photo.image;
}

最佳答案

我认为问题在于您没有在实际负责触发导航的代码中的任何地方调用 performSegueWithIdentifier:sender: 而不是 prepareForSegue:sender: 这是准备导航时调用

所以我建议实现 collectionView:didSelectItemAtIndexPath: 如下

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
Photo *selectedPhoto = self.photos[path.row];
// this line is the one that is responsible for navigation
[self performSegueWithIdentifier:@"Detail Segue" sender:selectedPhoto];
}

并修改prepareForSegue:sender:如下

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"Detail Segue"]) {
PhotoDetailViewController *PhotoDetailVC = segue.destinationViewController;
PhotoDetailVC.photo = sender;
}
}

关于ios - 在 UICollectionViewController 中按下 UICollectionViewCell 后无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064333/

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