[英]Instance method 'items' requires that 'listen' conform to 'Sequence'
I want to bind the value of tableViewCell.我想绑定tableViewCell的值。 But there is an error like the title.但是有一个像标题这样的错误。 I've never seen this error before and I want to know how to fix it.我以前从未见过这个错误,我想知道如何解决它。
func bindViewModel() {
let input = ListenViewModel.input(loadData: loadData.asSignal(onErrorJustReturn: ()))
let output = viewModel.transform(input)
output.loadApplyList.bind(to: tableView.rx.items) { tableView, index, element -> UITableViewCell in
guard let cell = self.tableView.dequeueReusableCell(withIdentifier: "ListeningTableViewCell") as? ListeningTableViewCell else {
return ListeningTableViewCell()}
cell.listeningData = element
}.disposed(by: disposeBag)
}
This is my ViewController Code这是我的 ViewController 代码
class ListenViewModel: ViewModelType {
private let disposeBag = DisposeBag()
static var loadData = PublishRelay<listen>()
struct input {
let loadData: Signal<Void>
}
struct output {
// let isEnabled: Driver<Bool>
let result: Signal<String>
let loadApplyList: PublishRelay<listen>
}
func transform(_ input: input) -> output {
let api = ProfileAPI()
let result = PublishSubject<String>()
let loadApplyList = PublishRelay<listen>()
input.loadData.asObservable().subscribe(onNext: { [weak self] in
guard let self = self else { return }
api.getListenigList("admin123@gmail.com").subscribe(onNext: { (response, statuscode) in
switch statuscode {
case .ok:
if let response = response {
loadApplyList.accept(response)
}
case .noHere: result.onNext("fail")
default:
print("Default")
}
}).disposed(by: self.disposeBag)
}).disposed(by: disposeBag)
return output(result: result.asSignal(onErrorJustReturn: "실패"), loadApplyList: loadApplyList)
}
}
And this is my ViewModel Code.这是我的 ViewModel 代码。 How to fix this error?如何修复此错误?
To bind to a table view's items
, you need a sequence of things, like an array, for example.要绑定到表视图的items
,您需要一系列事物,例如数组。 Each element of that sequence will be displayed on a cell.该序列的每个元素都将显示在一个单元格上。
You've got a listen
object here ( output.loadApplyList
), which isn't a sequence of things.你有一个listen
object 在这里( output.loadApplyList
),这不是一系列的事情。 If you just want to just display one cell, you should create a sequence with a single element.如果您只想显示一个单元格,您应该创建一个包含单个元素的序列。
There is a simple way to create a sequence with only a single element:CollectionOfOne
, so you should map
your listen
objects to that.有一种简单的方法可以创建一个只有一个元素的序列:CollectionOfOne
,所以你应该map
你的listen
对象。
output.loadApplyList.map(CollectionOfOne.init).bind(to: tableView.rx.items) { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.