Ios 未调用CollectionView didSelectItemAt

Ios 未调用CollectionView didSelectItemAt,ios,objective-c,swift,xcode,uicollectionview,Ios,Objective C,Swift,Xcode,Uicollectionview,回购: 我有一个collectionView,想通过单击一个项目来执行一个序列。 问题是,当我单击某个项目时,没有调用didSelectItemAt。我尝试了不同的模拟器和真实的设备。 尽管长时间点击contextMenuConfigurationForItemAt可以正常工作 class RecordsCollectionViewController: UICollectionViewController { override func collectionView(_ collectio

回购:

我有一个collectionView,想通过单击一个项目来执行一个序列。 问题是,当我单击某个项目时,没有调用didSelectItemAt。我尝试了不同的模拟器和真实的设备。 尽管长时间点击
contextMenuConfigurationForItemAt
可以正常工作

class RecordsCollectionViewController: UICollectionViewController {
  override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
      let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil){ action in
          let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash.fill"), identifier: nil,discoverabilityTitle: nil, attributes: .destructive, handler: {action in
              self.deleteItem(index: indexPath.item)
          })
          
          return UIMenu(title: "", image: nil, identifier: nil, children: [delete])
      }
      
      return configuration
  }
  
  // MARK: UICollectionViewDataSource
  
  override func numberOfSections(in collectionView: UICollectionView) -> Int {
      
      return 1
  }

  
  override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
      
      return distancesArray.count
  }
  
  override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
      if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as? RecordsCollectionViewCell {
          cell.setupCell(distance: distancesArray[indexPath.item])
          
          return cell
      }
      
      return UICollectionViewCell()
  }
  
  override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      print("not getting called")
      performSegue(withIdentifier: showRecordsTVCsegue, sender: self)
  }
}
单元格如下所示:

class RecordsCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var distanceTextView: UILabel!
    
    let formatter = NumberFormatter()
    
    func setupCell(distance: Int32) {
        let formatter = NumberFormatter()
        
        formatter.minimumFractionDigits = 0
        formatter.maximumFractionDigits = 2
        
        if distance >= 1000 {
            self.distanceTextView.text = "\(formatter.string(from: NSNumber(value: Double(distance) / 1000)) ?? "") km"
        } else {
            self.distanceTextView.text = "\(distance) m"
        }
        
        self.layer.cornerRadius = 25
        self.clipsToBounds = true
    }
    
}
我尝试了不同的解决方案,但没有一个对我有帮助。 比如说

        collectionView.allowsSelection = true
        collectionView.isUserInteractionEnabled = true

我也不使用手势识别器。

检查了您的回购协议并找到了解决方案

转到xib中的recordsCell->ContentView并删除自定义类RecordsCollectionViewCell如屏幕截图所示


检查您的回购协议并找到解决方案

转到xib中的recordsCell->ContentView并删除自定义类RecordsCollectionViewCell如屏幕截图所示


这是一个单元格,上面有一些视图,比如UIButton?你的手机看起来怎么样?我只有一个标签,显示距离@IBOutlet弱var距离文本视图:UILabel@ArtiomLemiasheuski尝试删除这两行代码只是为了进行一个小检查:
self.layer.cornerRadius=25
self.clipstobunds=true
不幸的是,我没有帮上忙,我抓起了你的GitHub报告。。。有件很奇怪的事我想不出来。使用“调试视图层次结构”时,它会显示您的单元格是否具有嵌入的单元格?没有道理。。。我在情节提要中删除并重新构建了您的
记录CollectionViewController
,并且(在代码中添加
didSelectItemAt
后),它工作正常。它是一个单元格,上面有一些视图,比如UIButton?你的手机看起来怎么样?我只有一个标签,显示距离@IBOutlet弱var距离文本视图:UILabel@ArtiomLemiasheuski尝试删除这两行代码只是为了进行一个小检查:
self.layer.cornerRadius=25
self.clipstobunds=true
不幸的是,我没有帮上忙,我抓起了你的GitHub报告。。。有件很奇怪的事我想不出来。使用“调试视图层次结构”时,它会显示您的单元格是否具有嵌入的单元格?没有道理。。。我在情节提要中删除并重新构建了您的
记录CollectionViewController
,并且(在代码中添加
didSelectItemAt
后),它工作正常。