1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[RxCocoa]プログラムからテキストを変更した場合, textField.rx.textにイベントが流れない

Last updated at Posted at 2022-01-18

textField.text = "hogehoge"とプログラムからtextを変更しただけではtextField.rx.textにイベントが流れてくれない。

RxCocoaのソースを見ると.valueChangedイベントが流れた時にrx.textが更新されるようである。そのため、textField.sendActions(for: .valueChanged)として、明示的にイベントを流せば良い。

UIControl+Rx.swift
    /// This is a separate method to better communicate to public consumers that
    /// an `editingEvent` needs to fire for control property to be updated.
    internal func controlPropertyWithDefaultEvents<T>(
        editingEvents: UIControl.Event = [.allEditingEvents, .valueChanged],
        getter: @escaping (Base) -> T,
        setter: @escaping (Base, T) -> Void
        ) -> ControlProperty<T> {
        return controlProperty(
            editingEvents: editingEvents,
            getter: getter,
            setter: setter
        )
    }

参考 https://stackoverflow.com/questions/45633173/how-do-you-get-a-signal-every-time-a-uitextfield-text-property-changes-in-rxswif

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?