Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-[RxCocoa.RxTextViewDelegateProxy text]: unrecognized selector sent to instance 0x28132bdb0 #2571

Closed
1 task done
make1a opened this issue Dec 25, 2023 · 2 comments
Closed
1 task done

Comments

@make1a
Copy link

make1a commented Dec 25, 2023

Short description of the issue:

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

⚠️ 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. ⚠️

Installation method:

  • CocoaPods

crash log:

Fatal Exception: NSInvalidArgumentException
-[RxCocoa.RxTextViewDelegateProxy text]: unrecognized selector sent to instance 0x28132bdb0

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0xec870 __exceptionPreprocess
1  libobjc.A.dylib                0x2bc00 objc_exception_throw
2  CoreFoundation                 0x17d19c +[NSObject(NSObject) _copyDescription]
3  CoreFoundation                 0x31ff8 ___forwarding___
4  CoreFoundation                 0x172b10 _CF_forwarding_prep_0
5  ContextKitExtraction           0x907c +[CKContextContentProviderUIScene _bestVisibleStringForView:usingExecutor:]
6  ContextKitExtraction           0x8154 +[CKContextContentProviderUIScene _donateContentsOfWindow:usingExecutor:withOptions:]
7  ContextKitExtraction           0x7908 __78+[CKContextContentProviderUIScene extractFromScene:usingExecutor:withOptions:]_block_invoke
8  ContextKitExtraction           0x6688 __64-[CKContextExecutor addWorkItemToQueue:withWorkItem:andContext:]_block_invoke
9  libdispatch.dylib              0x26a8 _dispatch_call_block_and_release
10 libdispatch.dylib              0x4300 _dispatch_client_callout
11 libdispatch.dylib              0x129e0 _dispatch_main_queue_drain
12 libdispatch.dylib              0x125b0 _dispatch_main_queue_callback_4CF
13 CoreFoundation                 0x3720c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
14 CoreFoundation                 0x33f18 __CFRunLoopRun
15 CoreFoundation                 0x33668 CFRunLoopRunSpecific
16 GraphicsServices               0x35ec GSEventRunModal
17 UIKitCore                      0x22c2b4 -[UIApplication _run]
18 UIKitCore                      0x22b8f0 UIApplicationMain
19 HelloTalk_Binary               0x54ff7f8 main + 25 (main.m:25)
20 ???                            0x1baf12dcc (缺少)
@make1a
Copy link
Author

make1a commented Dec 25, 2023

#2428

Can I fix it with the following code?

@objc
extension RxTextViewDelegateProxy {
    var text: String {
        return String()
    }
}

@faimin
Copy link
Contributor

faimin commented Dec 25, 2023

#2546

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants