ios - items' 产生 '(Source) -> Disposable' ,而不是 UICollectionLayout 的预期上下文结果类型 '(_) -> _' 错误

标签 ios rx-swift

我有一个包含 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/

相关文章:

ios - Rxswift3.0 中的 throttle 和 debounce 有什么区别?

ios - 更新约束值不起作用IOS 9 Beta

objective-c - 如何使用 Core Plot 设置图表宽度?

ios - Aviary SDK框架问题

ios - 在 iOS 中加载特定日期和时间的图像

ios - Swft3 (RxSwift, RxCocoa) - 使用响应式(Reactive)编程的 TableView 展开和折叠概念

objective-c - iOS 应用程序中的 sinf() 和 cosf()

ios - RxSwift 的结构 View 模型

ios - Rx swift : Is it safe to always use [unowned self] when a class has a disposeBag property?

ios - 是否可以同时绑定(bind)两个观察者?