简体   繁体   English

实例方法“items”要求“listen”符合“sequence”

[英]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.

相关问题 实例方法 'items(cellIdentifier:cellType:)' 要求 'Model' 符合 'Sequence' - Instance method 'items(cellIdentifier:cellType:)' requires that 'Model' conform to 'Sequence' 实例方法要求“ NSObject”符合 - Instance method requires that 'NSObject' conform 实例方法“包含”要求“UITextField”符合“StringProtocol” - Instance method 'contains' requires that 'UITextField' conform to 'StringProtocol' Generics 和约束(`实例方法'...'要求'T'符合'Decodable'') - Generics and Constraints (`Instance method '…' requires that 'T' conform to 'Decodable'`) 错误:实例方法 'onReceive(_:perform:)' 要求 'Int' 符合 'Publisher' - Error: Instance method 'onReceive(_:perform:)' requires that 'Int' conform to 'Publisher' 实例方法 'save(_:where:completion:)' 要求 'PostModel' 符合 'Model' - Instance method 'save(_:where:completion:)' requires that 'PostModel' conform to 'Model' Swift:For-in 循环需要“[DeepSpeechTokenMetadata]”以符合“Sequence” - Swift: For-in loop requires '[DeepSpeechTokenMetadata]' to conform to 'Sequence' 为什么我收到错误“实例方法 'fill(_:style:)' 要求 'some View' 符合 'ShapeStyle'”? - Why am I getting the error "Instance method 'fill(_:style:)' requires that 'some View' conform to 'ShapeStyle'"? Swift Array 按属性排序错误:实例方法“localizedCaseInsensitiveCompare”需要“String?” 符合 &#39;StringProtocol&#39; - Swift Array Sort by Property Error : Instance method 'localizedCaseInsensitiveCompare' requires that 'String?' conform to 'StringProtocol' VStack 显示错误“实例方法 'sheet(item:onDismiss:content:)' 要求 'Int' 符合 'Identifiable'” - VStack shows error "Instance method 'sheet(item:onDismiss:content:)' requires that 'Int' conform to 'Identifiable'"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM