【发布时间】:2020-04-13 22:14:53
【问题描述】:
我要求实现 MVVM 设计模式,所以这里我有一个 HomeViewController
其中包含一个 HomeViewModel ,HomeViewController 在 MVVM 中有一个 tableView 和一些其他 UIKit 组件我读到每个 UIView 都应该有自己的 ViewModel所以对于 UITableView (HomeTableViewCell) 的单元格,每个单元格都应该有自己的 ViewModel ,所以 HomeViewModel 是否应该包含将传递给每个单元格的单元格的 SubViewModels 集合,或者它的正确实现是什么,最好的情况?
extension HomeViewController : UITableViewDelegate , UITableViewDataSource{
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel?.articlesCount ?? 0
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
}
}
【问题讨论】:
标签: ios swift design-patterns mvvm uikit