【发布时间】:2016-08-01 12:41:10
【问题描述】:
下午好,
我正在尝试从我的 CollectionView 执行 segue,但在触摸 Cell 时不会触发 prepareForSegue。这适用于我的 TableView,但不适用于我的 CollectionView。
正如你在我的代码中看到的,我在同一个 ViewController 中都有,但我不知道为什么它只适用于 TableView。 “segueCollection”永远不会被触发。
我必须做什么才能完成这项工作?存在某种类型的问题,因为我也在使用 TableView segue?我有点迷路了。
这是我的代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showMovieFromTable", let destination = segue.destinationViewController as? MovieViewController, index = tableView.indexPathForSelectedRow?.row {
destination.year = searchMovies[index].year
} else if segue.identifier == "showMovieFromCollection" {
print("segueCollection")
}
print("segueTriggered")
}
我也在尝试这段代码(但它也没有显示任何内容):
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print(indexPath)
self.performSegueWithIdentifier("showMovieFromCollection", sender: self)
}
提前致谢,
问候。
【问题讨论】:
-
“我必须做什么才能完成这项工作?”是的,让我们知道。您如何将 segue 附加到集合中
-
我@Lu_,我已将 CollectionViewCell 中的 Cell 中的“选择”选项连接到 Storyboard 中的 MovieViewController。
-
你在哪里调用它(
performSegue:())?你是怎么设置的?比如你把segue从cell直接放到下一个VC,而不是把当前vc放到下一个vc,它不会被调用。 -
嗨@Larme,我已经用我称之为 performSegue 的地方更新了我的第一篇文章,但它仍然没有显示任何内容。
标签: ios swift swift2 uicollectionview segue