Ios 使用选择器视图筛选CollectionView

Ios 使用选择器视图筛选CollectionView,ios,swift,uicollectionview,uipickerview,Ios,Swift,Uicollectionview,Uipickerview,现在我在代码中使用UICollectionView扩展来显示我餐厅的所有菜单项。我想将其连接到视图控制器中的选择器视图,以根据产品类型筛选项目。这是我目前的代码: 集合视图 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.deque

现在我在代码中使用
UICollectionView
扩展来显示我餐厅的所有菜单项。我想将其连接到视图控制器中的选择器视图,以根据产品类型筛选项目。这是我目前的代码:

集合视图

   func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "productCells", for: indexPath) as! ProductCollectionCell

        let product = products[indexPath.item]


        }

        cell.burgerName.text = product.name?.capitalized
        cell.desc.text = product.size?.capitalized
        cell.desc.textColor = UIColor.white


        if let image = product.image {
            Helpers.loadImage(cell.productImage, "\(image)")
        }

        cell.layer.borderColor = UIColor.lightGray.cgColor
        cell.layer.borderWidth = 0.5

        return cell
    }
选择器视图

  func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        let view = UIView()
        view.frame = CGRect(x: 0, y: 50, width: width, height: 40)
//        view.backgroundColor = UIColor.darkGray
//        view.isOpaque = true

        let label = UILabel()
        label.frame = CGRect(x: 0, y: 15, width: width, height: 26)
        label.textAlignment = .center

        label.font = UIFont.systemFont(ofSize: 10)
        label.text = sections[row]
        label.textColor = UIColor.purple
        label.highlightedTextColor = UIColor.darkText
        view.addSubview(label)

        // view rotation
        view.transform = CGAffineTransform(rotationAngle: 90 * (.pi/180))

        return view
    }


    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

        filteredProducts = self.products.filter({ (prod: Product) -> Bool in
            return prod.filter?.lowercased().range(of: UICollectionView())
        })

    }
我不确定如何根据变量部分进行过滤。这是名为Type的
products[indexPath.item]
的另一个变量。因此,当PickerView到达该类型时,我希望collectionview仅显示该类型的项目


任何帮助都将不胜感激。

您是否询问如何筛选数据源?或者如何选择单个项目?过滤CollectionView的数据源,以仅查看基于PickerView的项目。Picker视图直接显示正在使用switch语句表示如果“Pickerview==早餐”仅显示值为“早餐”的项目的信息