2017-08-19 42 views
0

ユーザーが入力中に遅延を伴う状態を示す必要があります。私はRxSwiftを使用しようとしている:RxSwiftを使用した場合の問題

_textField.rx.text.orEmpty.debounce(3, scheduler: MainScheduler.instance).distinctUntilChanged().subscribe({[weak self] _ in 
     self?.typeViewShould(hide: true) 
    }).addDisposableTo(disposeBag) 

問題は3秒後に、私は待ちたくあり、ブロックは、私はしていない一度だけ最新の値と、入力された文字と同じ回数を実行します。私はGitHubの例検索からのコードを書き換えることを試みたが、それは動作しません:

 _ = _textField.rx.text.orEmpty.debounce(3, scheduler: MainScheduler.instance).distinctUntilChanged().flatMapLatest {[weak self] query -> Observable<[String]> in 
     self?._textField.text = nil 
     self?.typeViewShould(hide: true) 
     return .just([]) 
    }.observeOn(MainScheduler.instance) 

を私が間違っているのか?

答えて

0

'デバウンス' 次のように動作します - http://rxmarbles.com/#debounce

私が正しくあなたの質問を理解していれば、あなたはこのような何かしたい -

 let timer = Observable<Int>.timer(3.0, scheduler: scheduler) 
     let textAfter3Seconds = Observable.combineLatest(timer, _textField.rx.text) { $1 } 
関連する問題