首页 > 解决方案 > 无法在 RxDataSources 中推断通用参数“Self”

问题描述

我正在为简单的 TableView尝试 RxDataSources https://github.com/RxSwiftCommunity/RxDataSources

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        let items = [
            CustomItem(id: 12, title: "name"),
            CustomItem(id: 22, title: "your age"),
            CustomItem(id: 77, title: "style")
        ]

        let data = Observable<[CustomItem]>.just(items)

        data.bind(to: tableView.rx.items(cellIdentifier: "CustomCell", cellType: CustomCell)) {
            index, model, cell in
            cell.questionLbl.text = model
            }
            .disposed(by: disposeBag)
    }

}

class CustomCell: UITableViewCell {
    @IBOutlet weak var questionLbl: UILabel!
}

struct CustomItem: Equatable {
    let id: Int
    let title: String

    static func == (lhs: CustomItem, rhs: CustomItem) -> Bool {
        return lhs.id == rhs.id
    }
}

我得到了这个错误:

无法推断通用参数“Self”

ps 如您所见 - 我将 Equatable 添加到我的结构中,但它也不起作用。同时,如果我将自定义对象数组更改为字符串数组,一切都会开始正常工作。

标签: iosswiftrx-swiftrx-cocoa

解决方案


推荐阅读