Reactive Cocoa - UITextView rac_textSignal not called when programmatically setting text

I implement the chat user interface and use Reactive Cocoa to adjust the size of the chat bubbles according to the type of user. I am currently updating the user interface layout based on textview rac_textSignal . Everything works fine - except for one bit: when the user sends a message, I programmatically clear the text field:

 _inputTextView.text = @""; 

... but the text rac_textSignal not activated. I heard this is a function with ReactiveCocoa - but what is the right way to build this? Do I need to have an NSString containing currentlyTypedString and manage user interface changes when updating this line?

+7
ios objective-c uitextfield reactive-cocoa
source share
3 answers

Yes, that's right.

In MVVM, the presentation model should be considered as a canonical source of data and user interface events (which leads to a number of important advantages, like better testability). You saved the printed NSString in the view model, and then bind it to the user interface.

With MVC, you have to use a controller or model instead, but the principle is the same: treat the view as temporary data and do important things elsewhere.

+7
source share

Just submit the action:

[self.inputTextView sendActionsForControlEvents: UIControlEventEditingChanged];

+9
source share

The following is a workaround:

 [[RACSignal merge:@[self.inputTextView.rac_textSignal, RACObserve(self.inputTextView, text)]] subscribeNext:^(NSString* text) { // do something here }]; 

Thanks to startupthekid on GitHub.

0
source share

All Articles