gpt4 book ai didi

ios - 未从 Collection View 调用 prepareForSegue

转载 作者:行者123 更新时间:2023-11-28 11:55:56 24 4
gpt4 key购买 nike

我在单个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com