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