我们目前正在为一个项目建立架构,我很难想象出完整的解决方案来解决这个问题。目前,我们有一个带有多个动态原型的集合视图,并且我们为每个单元格子类化其中一个。我想知道是否有一种方法可以做类似于以下的事情。
在像collectionView(_:cellForItemAt :) / collectionView(_:didSelectItemAt :)这样的方法中,同时遵循MVVM模式。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCell(withReuseIdentifier: viewModel.reuseIdentifierForIndexPath(indexPath), for: indexPath)
//update cell here in a generic way based on the class of this cell (we have this information)
return cell
}
基本上,我们想避免做以下这些事情:
if indexPath.row == 0 {
//do stuff for this specific cell
}
在像collectionView(_:cellForItemAt :) / collectionView(_:didSelectItemAt :)这样的方法中,同时遵循MVVM模式。