没有从集合视图中调用prepareForSegue

时间:2018-06-21 18:58:34

标签: ios swift uicollectionview

我正在单个视图控制器中实现多个集合视图。一切正常。在集合视图中,当我调用didSelect方法时,必须将ID传递给下一个视图控制器。我使用了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 ")
    }
} 

这是第二个视图控制器:

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

    override func viewDidLoad() {
        super.viewDidLoad()

        print("IDValues",iddata as Any)
    }

IDValues的值为空。 如何将ID传递给下一个视图控制器?

1 个答案:

答案 0 :(得分:2)

方法签名不正确。看起来应该如下图,

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

}