首页 > 解决方案 > 我应该在哪里用 VIPER 在 UICollectionView 中的 didSelectItemAt 中编写逻辑?

问题描述

我有一个带有 VIPER 的 UICollectionView:

//MARK: - UICollectionViewDataSource
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return presenter?.getCertsCount(status: getCertStatus()) ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? MyCertificationCell {
            if let certs = presenter?.getCerts(status: getCertStatus()) {
                cell.cert = certs[indexPath.item]
            }
            
            return cell
        }
        
        return UICollectionViewCell()
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }

但是当didSelectItemAt发出网络请求或推送新的 ViewController 时,我应该在哪里编写逻辑。在PresenterInteractorViewModel中?

标签: iosswiftmvvmviper-architecture

解决方案


推荐阅读