我尝试使用 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/