markohlebar / BIND

Data Binding and MVVM for iOS
MIT License
354 stars 48 forks source link

Two way binding of View-Model with a UITextField. #27

Closed Anupdas closed 8 years ago

Anupdas commented 8 years ago

Could you please point out how a two way binding can be done with a ViewModel and UITextField. From the example given it is quite easy to figure out the left to right assignments, but how can the right to left assignment be done.

I tried something like this, but this didn't make any change in the view model. BINDViewModel(point,<>, pointField.text)

Thanks.

markohlebar commented 8 years ago

Hey @Anupdas, this is a special case since UITextField doesn't raise KVO events when text is changed. You can use the onEditingChanged to bind the point to text field's text. Two way binding won't work out of the box for now I think. Maybe we need to modify UITextField+BNDBinding with a different property, like bnd_text which would do that.

Anupdas commented 8 years ago

Thanks for your reply. By fiddling with the code I found that if I do another right to left assignment using the onEditingChanged event it is possible to achieve what I'm looking for. I would share it to make it useful to others.

BINDViewModel(point,~>, pointField.text) BINDViewModel(point,<~, pointField.onEditingChanged)