我有一个 method
归来的 Single
:
func getEventStatus() throws -> Single<EventModel?> {
return try mainService.getEventStatus()
}
我想 bind
其为 tableView
却得到了 error
说它不能在 Singles
,所以我试着添加 .asObservable()
但现在我得到的是 error
表达式'Reactive<_>'在没有更多上下文的情况下是模糊不清的。
我试着查了一下它的意思,但似乎没有任何一致的说法。error
的意思,或者说我似乎无法将其应用到我的案例中。这就是 bind
的样子。
viewModel.getEventStatus().asObservable().bind(to: tableView.rx.items(cellIdentifier: EventLogTableViewCell.identifier, cellType: EventLogTableViewCell.self)) { row, data, cell in
cell.viewModel = data
}.disposed(by:disposeBag)
正如... method
throws
我补充道 do { try catch{} }
但这似乎并没有什么不同。
我在这里遗漏了什么?
问题出在你的方法的签名上。
你的方法的 getEventStatus()
方法只发出一个 EventModel
也是 Optional
.
该 items(cellIdentifier:cellType:)
方法需要一个数组的东西。