Rxswift: Subscribing to UITextField Control Event hides keyboard

Created on 30 Apr 2017  路  4Comments  路  Source: ReactiveX/RxSwift

Hi, when I subscribe to UITextField like this, when user press "done" button, keyboard is dismissed. It's not what I want, because in my case I want to clear textfield and allow user input another text into it.

           // because of that code, keyboard dismiss :(
            textField.rx.controlEvent(UIControlEvents.editingDidEndOnExit)
                .subscribe(onNext: { [weak self] _ in
                    guard let text = textField.text, text.isNotEmpty else { return }
                    // do sth
                    textField.text = nil
                })
                .addDisposableTo(self.bag)

how to handle button and keep first responder on the same uitextfield?

Most helpful comment

Any ideas how to handle Done/Return/Search button of UITextField with RxCocoa?

All 4 comments

Hi @adamsmaka ,

This is a UIKit question and not Rx question, sorry.

Try searching for becomeFirstResponder or some other way.

Any ideas how to handle Done/Return/Search button of UITextField with RxCocoa?

Hi @kzaher I believe this is actually a problem specific with RxSwift and this issue should be reopened.

The standard behavior with UIKit is the keyboard does not hide when the user selects the Return Key, this is functionality that needs to be specified. However when utilising textField.rx it now automatically hides. This is not expected behavior or behavior in line with UIKit.

@bnussey If you believe that this is a RxSwift bug and that we are doing something wrong, feel free to make a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tyregor picture tyregor  路  3Comments

trungp picture trungp  路  3Comments

retsohuang picture retsohuang  路  3Comments

acecilia picture acecilia  路  3Comments

RafaelPlantard picture RafaelPlantard  路  3Comments