Uitableview 为什么方法didDeselectItemAt不调用?

Uitableview 为什么方法didDeselectItemAt不调用?,uitableview,uikit,cell,uicollectionviewcell,collectionview,Uitableview,Uikit,Cell,Uicollectionviewcell,Collectionview,我有个问题。 我在tableView中嵌入了一个集合视图。 我存储选定项的indexPath(用于在重用单元格后恢复它们的状态)。 问题是:当我选择项目时,向下滚动并向上滚动-我选择的项目正在存储状态,但我无法取消选择项目。方法diddiselectionItem不调用 extension CategoryCollectionCell: UICollectionViewDataSource { func collectionView(_ collectionView: UICollect

我有个问题。 我在tableView中嵌入了一个集合视图。 我存储选定项的indexPath(用于在重用单元格后恢复它们的状态)。 问题是:当我选择项目时,向下滚动并向上滚动-我选择的项目正在存储状态,但我无法取消选择项目。方法diddiselectionItem不调用

extension CategoryCollectionCell: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        items?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CategoryCell.identefier, for: indexPath) as! CategoryCell
        let currentItem = items?[indexPath.row]
        cell.config(text: currentItem?.name ?? "")
        cell.isSelected = currentItem?.isSelected ?? false
        cell.layoutIfNeeded()
        return cell
    }
}

extension ImmoFilterCategoryCollectionCell: UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        items?[indexPath.row].isSelected = true
        delegate?.update(attributes: items, indexPath: self.indexPath)
    }
    
    func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
        items?[indexPath.row].isSelected = false
        delegate?.update(attributes: items, indexPath: self.indexPath)
    }
}
delegate?.update-存储indexPath的方法

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Cell, for: indexPath) as! Cell
        guard let currentItem = items?[indexPath.row] else { return cell}
        cell.config(text: currentItem.name )
        if  currentItem.isSelected {
            self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .bottom)
            cell.isSelected = true
        }
        return cell
    }
这是我的工作