S
S
Shakedown2022-02-21 11:30:57
iOS
Shakedown, 2022-02-21 11:30:57

Why is a cell not being clicked in UICollectionView?

Hello. I have 2 UICollectionView on different controllers which I fill with photos. The code for these collection views is identical, but for some reason, on one controller, the collection view handles clicking on the cell, and on the other controller, you have to make a long press on the cell in order for the click to be processed. Tried debugging, didn't find anything. Also collection views do not overlap other views. What could be the problem?

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return images.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "searchingCell", for: indexPath) as! SearchingCollectionViewCell
        cell.configure(stringUrl: images[indexPath.row].fullUrl)
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            collectionView.deselectItem(at: indexPath, animated: true)
            
            let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            guard let viewController = storyboard.instantiateViewController(withIdentifier:  "DetailImageViewController") as? DetailImageViewController else { return }
            viewController.modalPresentationStyle = .fullScreen
            viewController.wallpaperImage = self?.images[indexPath.row]
            
            self?.present(viewController, animated: true, completion: nil)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let frameCollectionView = collectionView.frame
        let cellWidth = frameCollectionView.width / CGFloat(countCells)
        let cellHeight = CGFloat(250)
        
        return CGSize(width: cellWidth - offsetCells, height: cellHeight - offsetCells)
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2022-02-21
@briahas

Check the settings in the storyboards for both collection views. Maybe they misclicked there and attached the method to the wrong place?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question