Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 将数据从集合视图传递到视图控制器_Swift - Fatal编程技术网

Swift 将数据从集合视图传递到视图控制器

Swift 将数据从集合视图传递到视图控制器,swift,Swift,我无法将数据从集合ViewController正确传递到ViewController。在vc上显示相同的商品。我不明白我的错误在哪里 struct Goods { var goods = [String]() } var namesOfGoods = [Goods(goods: ["Good1", "Good2", "Good3"]), Goodsl(goods: ["Good4", "Good5", "Good6"])

我无法将数据从集合ViewController正确传递到ViewController。在vc上显示相同的商品。我不明白我的错误在哪里

   struct  Goods {
        var goods = [String]()
    }
     var  namesOfGoods = [Goods(goods: ["Good1", "Good2", "Good3"]),
                Goodsl(goods: ["Good4", "Good5", "Good6"]),
                Goods(goods: ["Good7"])]

class ProductsCollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

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

        if segue.identifier == "show" {
            var productDetailVC = segue.destination as! DescriptionProductViewController
            let cell = sender as! UICollectionViewCell
            let indexPath = collectionView.indexPath(for: cell)
            let product = Goods[(indexPath?.row)!]
            productDetailVC.name = product
        }

    }

class DescriptionProductViewController: UIViewController {


    var name: Goods!

    @IBOutlet weak var productIamge: UIImageView!
    @IBOutlet weak var priceLabel: UILabel!
    @IBOutlet weak var nameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        nameLabel.text = name.joined(separator: "")

    }
名称是结构而不是数组。 更改此行:

nameLabel.text = name.joined(separator: "")
致:


这个名字也是很坏的变量名。你应该考虑重命名它。

你能显示你的DestSuestTimAT实现吗?嗯,OP似乎更愿意离开这个平台而不是显示需要的代码。投票结束。
nameLabel.text = name.goods.joined(separator: "")