crash on -[RxCocoa.RxTextViewDelegateProxy text]: unrecognized selector sent to instance 0x28132bdb0
private let userInputSubject = PublishSubject<String>()
private let emoticonsRelay = BehaviorRelay<[Emoticon]>(value: [])
private var disposeBag = DisposeBag()
{
// 用户3秒没有操作输入框,没有滑动,就隐藏
userDidInteract()
textView?.rx.didChange
.subscribe(onNext: { [weak self] in
if let text = self?.textView?.text {
self?.userInputChanged(text: text)
}
})
.disposed(by: disposeBag)
// 1.长度超过15的文本不请求接口, 2.milliseconds(500)再请求接口
userInputSubject
.filter { [weak self] text in
guard let self = self else { return false }
return text.count <= self.maxCount
}
.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
.flatMapLatest { [weak self] text -> Observable<[Emoticon]> in
guard let self = self else { return .empty() }
return self.requestEmoticons(text)
}
.bind(to: emoticonsRelay)
.disposed(by: disposeBag)
// rx
let dataSource = RxCollectionViewSectionedReloadDataSource<SectionModel<String, Emoticon>> { _, collectionView, indexPath, item in
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ChatRelatedEmoticonCell.identifier, for: indexPath) as? ChatRelatedEmoticonCell else {
return UICollectionViewCell()
}
cell.refresh(with: item)
return cell
}
// 监听单元格选择事件
collectionView.rx.modelSelected(Emoticon.self)
.subscribe(onNext: { [weak self] emoticon in
self?.itemSelected(emoticon: emoticon)
})
.disposed(by: disposeBag)
// 绑定数据
emoticonsRelay
.observe(on: MainScheduler.instance)
.map { [SectionModel(model: "", items: $0)] }
.bind(to: collectionView.rx.items(dataSource: dataSource))
.disposed(by: disposeBag)
// 根据数据源来决定是否隐藏 ChatRelatedEmoticonView
emoticonsRelay
.asDriver()
.drive(onNext: { [weak self] emoticons in
guard let `self` = self else { return }
let textEmpty = self.textView?.text.isEmpty ?? true
let dataEmpty = emoticons.isEmpty
let isVisible = !textEmpty && !dataEmpty
if isVisible {
self.isHidden = false
self.resetTimer()
} else {
self.isHidden = true
}
let jsonStr = self.jsonStr() ?? ""
self.delegate?.chatRelatedEmoticonViewDidUpdateVisibility(isVisible: isVisible, jsonStr: jsonStr)
})
.disposed(by: disposeBag)
}
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
pod 'RxSwift', '6.6.0'
pod 'RxCocoa', '6.6.0'
pod 'RxRelay', '6.6.0'
Platform/Environment
iOS
Xcode version:
14.2
:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:
Short description of the issue:
crash on -[RxCocoa.RxTextViewDelegateProxy text]: unrecognized selector sent to instance 0x28132bdb0
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
pod 'RxSwift', '6.6.0' pod 'RxCocoa', '6.6.0' pod 'RxRelay', '6.6.0'
Platform/Environment
Xcode version:
:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:
Installation method:
crash log: