我有一个方法
,它返回一个single
:
func getEventStatus() throws -> Single<EventModel?> {
return try mainService.getEventStatus()
}
我试图将它绑定
到一个TableView
,但得到了一个错误
,说明它在single
上不起作用,所以我尝试添加.asobservable()
,但现在我得到了错误
表达式类型“reactive<_>” 在没有更多上下文的情况下是模棱两可的
我曾试图查找它的含义,但似乎与错误
的含义没有任何一致性,或者我似乎无法将其应用于我的案例。 绑定
如下所示:
viewModel.getEventStatus().asObservable().bind(to: tableView.rx.items(cellIdentifier: EventLogTableViewCell.identifier, cellType: EventLogTableViewCell.self)) { row, data, cell in
cell.viewModel = data
}.disposed(by:disposeBag)
当方法
抛出
时,我添加了do{try catch{}}
,但这似乎没有什么区别。
我错过了什么?
问题是你的方法的签名。
getEventStatus()
方法只发出一个EventModel
,即使它也是一个可选
。
items(celliDentifier:cellType:)
方法需要一个东西数组。