【问题标题】:prepareForSegue UICollectionView not working (swift)prepareForSegue UICollectionView 不工作(迅速)
【发布时间】:2015-06-13 05:57:05
【问题描述】:

我尝试使用 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 中工作,但在上面的代码中没有图像。

【问题讨论】:

    标签: ios swift xcode6 uicollectionview segue


    【解决方案1】:

    您需要添加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]
              }
        }
    }
    

    【讨论】:

    • 我从self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) 得到对成员collectionView 的模棱两可的引用。有其他解决方案吗?
    猜你喜欢
    • 1970-01-01
    • 2015-12-04
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    相关资源
    最近更新 更多