我有一个包含 UICollectionView 的自定义控件。这个自定义控件有自己的 View 模型。我正在使用 RXswift 进行 MVVM 设计。
View 模型类如下所示
class CalendarViewModel {
public var calendarNDays = PublishSubject<[CalendarControlDayModel]>()
struct CalendarControlDayModel {
var date: String = ""
var day: Int = 0
var name: String = ""
}
}
自定义控件称为 calendarView,我在其中创建上述 View 模型的实例并设置绑定(bind)以在 Collection View 中填充数据。
在自定义控件中设置绑定(bind)的方法如下所示。
func setUpBinding() {
calendarViewModel.calendarNDays.bind(to: collectionView.rx.items(cellIdentifier: cellReuseIdentifier, cellType: CalendarViewCell.self)) { (row,calendarDay,cell) in
cell.calendarDay = calendarDay
}.disposed(by: disposeBag)
}
但我收到上述方法的编译错误,显示为“项目”产生“(源)-> 一次性”,而不是预期的上下文结果类型“(_)-> _”
如果我将 calendarNDays 定义为自定义控件中的 publishSubject,它不会提示。关于这里有什么问题的任何提示。我想使用 View 模型中定义的属性设置绑定(bind),以显示 Collection View 项并符合 MVVM 设计模式。
最佳答案
我怀疑你已经定义了两个 CalendarControlDayModel
类型。一个在 CalendarViewModel
另一个在别处定义。检查并报告。
关于ios - items' 产生 '(Source) -> Disposable' ,而不是 UICollectionLayout 的预期上下文结果类型 '(_) -> _' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58244561/