-1

我使用IGListKit创建一个列表,每个单元格内都有一个collectionView。当我滚动列表时,触摸被识别为didSelectItemAt:在一个单元格中。我不知道为什么。这是我找到的一些堆栈信息。这是异常堆栈: 异常堆栈

这是我实际选择项目时的普通堆栈: 普通堆栈

let flowLayout = UICollectionViewFlowLayout().then {
    $0.minimumLineSpacing = 8
    $0.scrollDirection = .horizontal
}

lazy var collectionView: UICollectionView = {
    let collectionView = UICollectionView(frame: CGRect(x: 0, y: 64, width: recommendCellWidth, height: communityDiscussionCellHeight - 64), collectionViewLayout: flowLayout)
    collectionView.backgroundColor = .clear
    collectionView.showsHorizontalScrollIndicator = false
    collectionView.contentInset = UIEdgeInsets(top: 0, left: 20, bottom: 20, right: 20)
    collectionView.dataSource = self
    collectionView.delegate = self
    collectionView.register(SingleDiscussionCell.self, forCellWithReuseIdentifier: NSStringFromClass(SingleDiscussionCell.self))
    collectionView.register(LoadMoreCell.self, forCellWithReuseIdentifier: NSStringFromClass(LoadMoreCell.self))
    return collectionView
}()

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    6
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if indexPath.row == 5 {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(LoadMoreCell.self), for: indexPath) as? LoadMoreCell else {
            fatalError("invalid")
        }
        cell.bindViewModel(model: .communityDiscussion)
        return cell
    } else {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(SingleDiscussionCell.self), for: indexPath) as? SingleDiscussionCell else {
            fatalError("invalid")
        }
        if let model = discussions[safe: indexPath.row] {
            cell.bindViewModel(model: model)
        }
        return cell
    }
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if let model = discussions[safe: indexPath.row],
       let url = URL(string: model.schema) {
        // do sth
    }
}
4

0 回答 0