簡體   English   中英

在UICollectionView中永遠不會調用prepareForSegue

[英]prepareForSegue is never called in UICollectionView

下午好,

我正在嘗試從我的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)
}

提前致謝,

問候。

我遇到了同樣的問題,並在那里停留了一段時間。 最終我意識到,必須使用prepare函數,而不是使用prepareForSegue。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "YourIdentifier" {
        // stuff you want to do
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM