默认情况下调用 didSelectItemAt 项目大小的集合视图单元格而不是颜色集合视图单元格

didSelectItemAt item by default size collection view cell is called instead Color Collection View Cell

当时我应该调用颜色集合视图单元格 select item item at index Path..

extension ProductDetailViewController: UICollectionViewDataSource
{
       func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        if( collectionView .isEqual(sizeCollection))
        {
            return (size[section].product_option_value!.count) 
        }
        else
        {
            return (colorArray[section].product_option_value!.count)
        }
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        if (collectionView .isEqual(sizeCollection))
        {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sizecell", for: indexPath) as! SizeCollectionViewCell
        cell.sizeLabel.text = size[indexPath.section].product_option_value?[indexPath.item].name
        return cell
    }
        else
        {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "colorcell", for: indexPath) as! ColorCollectionViewCell

              DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {

           if let imageString = self.products[indexPath.section].images?[indexPath.item].thumb
           {

            if let imageUrl = URL(string:imageString)
            {
                if let imageData = try? Data(contentsOf: imageUrl)
                {
                    DispatchQueue.main.async {
                    cell.colorTypesOfImages.image = UIImage(data: imageData)
                        cell.colorLabel.text = self.colorArray[indexPath.section].product_option_value?[indexPath.item].name
                    }
                }}}}
                 return cell
        }
    }
}

extension ProductDetailViewController:UICollectionViewDelegate
{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
        if let imageString = self.products[indexPath.section].images?[indexPath.item].popup
        {

            if let imageUrl = URL(string:imageString)
            {
                if let imageData = try? Data(contentsOf: imageUrl)
                {
                    DispatchQueue.main.async {
                        self.productOriginalImage.image = UIImage(data: imageData)
                    }
                }}}
    }

请帮我解决这个问题。

extension ProductDetailViewController:UICollectionViewDelegate
{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
     if (collectionView .isEqual(sizeCollection))
        {
          // put you login for sizeCollection
        }
        else
        {
         // put you login for other collection     
       }
    }
}

尝试像这样更改 didSelectItemAt 代码

extension ProductDetailViewController:UICollectionViewDelegate
{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
        if (collectionView .isEqual(sizeCollection))
        {
            //sizeCollection
        }
        else {
            if let imageString = self.products[indexPath.section].images?[indexPath.item].popup
            {

                if let imageUrl = URL(string:imageString)
                {
                    if let imageData = try? Data(contentsOf: imageUrl)
                    {
                        DispatchQueue.main.async {
                            self.productOriginalImage.image = UIImage(data: imageData)
                        }
                    }}}
        }

    }
}     

注意:确保为两个集合视图提供委托和数据源。