Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle "Done" return key press event in rxSwift?

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".

like image 255
alex Avatar asked Oct 24 '15 10:10

alex


3 Answers

You can subscribe to UIControlEvents like this:

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

like image 76
louoso Avatar answered Nov 08 '22 20:11

louoso


In RxSwift 4 and 5:

textField.rx.controlEvent([.editingDidEndOnExit]).subscribe { _ in
    print("editingDidEndOnExit")
}.disposed(by: disposeBag)
like image 26
d.felber Avatar answered Nov 08 '22 22:11

d.felber


In Rxswift 3.0

textField.rx.controlEvent([.editingDidEndOnExit])
         .subscribe(onNext:{text in
            print(text)
         }).addDisposableTo(disposeBag)
like image 45
Chirag Desai Avatar answered Nov 08 '22 20:11

Chirag Desai