【问题标题】:No responed after pressing UICollectionViewCell in the UICollectionViewController在 UICollectionViewController 中按下 UICollectionView 后没有响应
【发布时间】:2015-10-11 11:16:12
【问题描述】:

当我将图像从 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(视图 B)中使用:

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

【问题讨论】:

  • 到底是什么问题?什么是预期的,但没有奏效?
  • 当我按下 UICollectionViewCell 时,应用程序没有响应,它应该与 View B @Mahmoud Adam
  • 那么你在哪里执行你的segue?您是否配置了集合视图的委托?你能在collectionView:didSelectItemAtIndexPath:方法中显示你的代码吗
  • 我在 UIcollectionViewController(视图 A)中执行我的 segue 我不使用 'collectionView:didSelectItemAtIndexPath:' 方法 @Mahmoud Adam
  • 您可以编辑帖子并添加此代码,因为它可能有问题

标签: ios objective-c uiviewcontroller uicollectionview segue


【解决方案1】:

我认为问题在于您没有在代码中实际负责触发导航的任何地方调用 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 的初学者,请建议我任何资源......?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多