ios - 未从 Collection View 调用 prepareForSegue

标签 ios swift uicollectionview

我在单个 View Controller 中实现多个 Collection View 。它工作正常。在 Collection View 中,当我调用 didSelect 方法时,我必须将 ID 传递给下一个 View Controller 。我使用了 prepareForSegue 但它没有调用。

这是代码:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if collectionView == self.FirstCollectionview
    {
    }
    else
    {
        let index : Int = indexPath.row
        let idvalues = info[index].category_id
        print("values",idvalues as Any)
        self.performSegue(withIdentifier: "DATA", sender: self)
    }
}

func prepareForsegue(segue: UIStoryboardSegue, sender: AnyObject) {
    if segue.identifier == "DATA" {
        let detailsview = segue.destination as? DetailsViewController
        detailsview?.id = sender as! String
        print("sendervalue",sender as Any)
    }else
    {
        print("not this ")
    }
} 

这是第二个 View Controller :

class DetailsViewController: UIViewController {
    var iddata : String = ""

    override func viewDidLoad() {
        super.viewDidLoad()

        print("IDValues",iddata as Any)
    }

IDValues 的值为空。 如何将 id 传递给下一个 View Controller ?

最佳答案

方法签名不正确。它应该如下所示,

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

}

关于ios - 未从 Collection View 调用 prepareForSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50975796/

相关文章:

objective-c - TableView 被委托(delegate),填充但不会分组

ios7 - UIActionSheet 与 swift

ios - 当用户选择一个单元格时,如何执行到 UITabBarController 中不同选项卡的转场?

swift - MLDataTable 中的多个目标列 - Swift 中的 CreateML 框架

swift - UICollectionView 单元格在滚动时重新计算大小(闪烁)

iOS 应用程序在 Release模式下崩溃,在 Debug模式下工作

ios - 如果删除实时应用程序的配置文件会发生什么?

ios - 使用自动布局将 UITableView 的高度设置为其内容的高度

ios - 在单元格之间的 UICollectionView 中设置/覆盖填充

ios - UIWindow 添加 subview 有什么缺点?