Monday, November 9, 2026
HomeiOS Developmentios - DidSelect a cell in Assortment View carried out in Assortment...

ios – DidSelect a cell in Assortment View carried out in Assortment View cell

[ad_1]

It is best to implement “didSelect” in ServiceCell

and it is best to implement in your ViewController “ought to spotlight” for first part to “false”

func collectionView(_ collectionView: UICollectionView, 
       shouldHighlightItemAt indexPath: IndexPath) -> Bool {
    return yourServiceSection ? false : true
}

the under code should be in ServiceCell and ViewController

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        collectionview.deselectItem(at: indexPath, animated: true)
 }

in your “ServiceCell” you could add this extension:

import Basis
import UIKit

extension ServiceCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection part: Int) -> Int {
        return viewModel.record.rely ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView,
                        cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier:
                                                        ServiceSubCell.nameOfClass,
                                                      for: indexPath) as? ServiceSubCell
        if let merchandise = viewModel.information?.merchandise(at: indexPath.merchandise) {
            cell?.config(merchandise: merchandise)
        }
        
        return cell ?? UICollectionViewCell()
    }
    
    func collectionView(_ collectionView: UICollectionView, format collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: SizeConstant.ServiceSubCellWidth.rawValue,
                      top: SizeConstant.ServiceSubCellHeight.rawValue)
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        collectionview.deselectItem(at: indexPath, animated: true)
// implement your code you want
    }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments