【问题标题】:How do I solve "Reactive<_>' is ambiguous" error in tableView context如何解决 tableView 上下文中的“Reactive<_>' is ambiguous”错误
【发布时间】:2020-06-05 10:03:03
【问题描述】:

我有一个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)

作为methodthrows,我添加了do { try catch{} },但这似乎没有什么区别。

我在这里错过了什么?

【问题讨论】:

    标签: ios swift uitableview rx-swift rx-cocoa


    【解决方案1】:

    问题在于您的方法的签名。

    getEventStatus() 方法只发出一个EventModel,甚至是一个Optional

    items(cellIdentifier:cellType:) 方法需要一个数组。

    【讨论】:

    • 感谢@Daniel,但是如何将其转换为数组?我试过try? viewModel.getEventStatus().asObservable().toArray().bind....,但它说“'PrimitiveSequence' has no member 'bind'”
    • 在EventModel周围加上括号,去掉问号。
    猜你喜欢
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    相关资源
    最近更新 更多