0

我正在使用 RxSwift 4.0 并使用构建 tableView 内容DTTableViewManager

在 Presenter 中,我有模型变量

1

lazy var mostRecent: TableTitleHeaderContainer = {
    let container = TableTitleHeaderContainer(isHidden: true, title: "Title 1")
    return container
}()

lazy var lastRecent: TableTitleHeaderContainer = {
    let container = TableTitleHeaderContainer(isHidden: false, title: "Title 2")
    return container
}()

型号代码

2

class TableTitleHeaderContainer {
    var subject: PublishSubject<Void> = PublishSubject<Void>()
    var isHidden: Bool
    var title: String
    var disposeBag = DisposeBag()
    init(isHidden: Bool, title: String) {
        self.isHidden = false
        self.title = title
    }
}

并使用模型查看配置

3

extension TableTitleHeaderView: ModelTransfer {
    func update(with model: TableTitleHeaderContainer) {
        clearButton.isHidden = model.isHidden
        clearButton.rx.tap
            .bind(to: model.subject).disposed(by: disposeBag)
        titleLabel.text = model.title
    }
}

我想听在 Presenter 中点击按钮

4

mostRecent.subject.asObserver().subscribe(onNext: { [weak self] (_) in
    print("Clear mostRecent")
}).disposed(by: disposeBag)

lastRecent().subject.asObserver().subscribe(onNext: { [weak self] (_) in
    print("Clear lastRecent")
}).disposed(by: disposeBag)

但是在Presenter中使用模型订阅配置视图后不调用?有什么问题?

4

0 回答 0