我有一个CollectionView。我想通过segue将选定的单元格索引发送到ViewController。为此我做了:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("Cell \(indexPath.row) selected!")
self.performSegueWithIdentifier("categoryItems", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "menuItems"{
var menuController = segue.destinationViewController as! MenuViewController
if let indexPath = collectionView.indexPathForCell(sender as! UICollectionViewCell) {
menuController.selectedCell = "\(indexPath.row)"
}
}
}
但它没有发送任何东西。问题是什么?我只想在ViewController中打印它,其中:
var selectedCell : String?
myLabel.text = selectedCell
我做错了什么?
答案 0 :(得分:0)
您已使用标识符
进行检查if segue.identifier == "menuItems"
并且您正在使用此标识符执行segue:
self.performSegueWithIdentifier("categoryItems", sender: self)
menuItems
不能神奇地变成categoryItems
,你自己要做点什么:)