当我将图像从 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/