26

While exploring RxSwift

I found just textField.rx_text.asObservable() property, that fires event every keyboard button is hit.

But how do we handle "search" or "done" button press events? I'd like to fire search only after these actions, not "search as you type".

4

3 回答 3

45

您可以像这样订阅 UIControlEvents:

textField.rx_controlEvents(.EditingDidEndOnExit).subscribeNext { print("return pressed") }

于 2015-10-25T02:40:19.573 回答
23

在 RxSwift 4 和 5 中:

textField.rx.controlEvent([.editingDidEndOnExit]).subscribe { _ in
    print("editingDidEndOnExit")
}.disposed(by: disposeBag)
于 2018-02-09T11:03:36.077 回答
6

Rxswift 3.0 中

textField.rx.controlEvent([.editingDidEndOnExit])
         .subscribe(onNext:{text in
            print(text)
         }).addDisposableTo(disposeBag)
于 2017-05-18T12:41:12.517 回答