【发布时间】:2017-10-14 05:11:42
【问题描述】:
这里我有一个模型类,我需要将选定的 sku 值从集合视图传递到另一个类中的表视图,谁能帮我实现这个?
这里是didselect item at index path方法的代码
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// Here you can check which Collection View is triggering the segue
if collectionView == firstCategory {
} else if collectionView == secondCategory {
// from other CollectionView
}else if collectionView == newCollection{
newPassedSku = newModel[indexPath.item].sku as? String
print(newPassedSku)
}else{
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "firstCategorySegue" {
_ = segue.destination as! ProductListViewController
}
else if segue.identifier == "secondCategorySegue" {
_ = segue.destination as! ProductListViewController
}else if segue.identifier == "newSegue"{
let detailsViewController = segue.destination as! ProductDetailsViewController
detailsViewController.index = newPassedSku
print(newPassedSku)
}
else {
_ = segue.destination as! ProductDetailsViewController
}
}
【问题讨论】:
-
func prepare(for segue被调用? -
它正在调用但无法传递我的价值@Mr.Bista
-
if segue.identifier == "newSegue"{条件满足? -
我尝试了一个新代码,但是在调用
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)之前发生了这种情况,它首先调用override func prepare(for segue: UIStoryboardSegue, sender: Any?),所以在其中传递了零值@Mr.Bista -
是的,它满足@Mr.Bista
标签: ios swift3 uicollectionview