ios - prepareForSegue UICollectionView 不工作(快速)

标签 ios swift xcode6 uicollectionview segue

我尝试使用 UICollectionView 来插入 segue(从 MasterView 到 DeatilView 显示图像),但不起作用。 Xcode 也不会显示任何错误消息。我的代码有什么问题。我需要一些建议。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

     if segue.identifier == "showDetail" {
      if let indexPath = self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) {
         let detailVC = segue.destinationViewController as! DetailMenuViewController
             detailVC.picFood = self.collection[indexPath.row]
  • 集合为空数组,获取json数据
  • [title = self.nameFood.title],它在 DetailMenuViewController.swift 中工作,但在上面的代码中不起作用。

最佳答案

您需要添加UICollecitonViewDelegate

func collectionView(collection: UICollectionView, selectedItemIndex: NSIndexPath) 
{
   self.performSegueWithIdentifier("showDetail", sender: self)
}

之后添加

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetail" {
          if let indexPath = self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) {
             let detailVC = segue.destinationViewController as! DetailMenuViewController
                 detailVC.picFood = self.collection[indexPath.row]
          }
    }
}

关于ios - prepareForSegue UICollectionView 不工作(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30815600/

相关文章:

ios - 如何测试静默通知在 iOS 中是否正常工作?

ios - 如何为 TableView 标题实现 UIVibrancyEffect?

ios - 从 Swift 中的另一个类访问 ViewController 类

ios - 顶部/底部布局指南受到限制的奇怪行为

objective-c - 如何将 NSUrl 转换为 NSString?

ios - 将触摸传递给 UIPopoverController 的底层按钮

ios - 展开 Segue Xcode 6.1 Swift

ios - XCode 6 测试版 Swift,SpriteKit : Changing Deployment Target

iOS获取UTC时间戳

swift - 在 Swift 4.2 中是否可以使用特定类型的 rawValue 将默认扩展写入枚举?