2015-06-13 4 views
2

Я попытался нажать сегу с помощью UICollectionView (показать форму изображения MasterView в DeatilView), но не работает. Xcode также не показывает сообщение об ошибке. Что не так с моим кодом. Мне нужен совет.prepareForSegue UICollectionView не работает (быстро)

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
  • [название = self.nameFood.title], она работает в DetailMenuViewController.swift, но не изображение на код выше.

ответ

2

Вы должны добавить 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] 
      } 
    } 
} 
+0

Я получаю неоднозначную ссылку на CollectionView члена от 'self.collectionView? .indexPathForCell (отправителем как! UICollectionViewCell)' , Есть ли альтернативное решение? – wxcoder