Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactive Cocoa - UITextView's rac_textSignal doesn't get called when programmatically setting text

I'm implementing a chat UI, and using Reactive Cocoa to adjust the chat bubble's size as the user types. Currently, I'm updating the UI's layout based on the textview's rac_textSignal. Everything's working great - except for one bit: when the user sends the message, I programmatically clear the textfield:

_inputTextView.text = @"";

... but the textview's rac_textSignal doesn't activate. I hear this is a feature with ReactiveCocoa - but what's the proper way to build this? Do I need to have an NSString holding the currentlyTypedString, and drive the UI changes when that string updates?

like image 416
bryanjclark Avatar asked Nov 25 '13 07:11

bryanjclark


2 Answers

Just send action:

[self.inputTextView sendActionsForControlEvents:UIControlEventEditingChanged];

like image 138
Ruslan Mansurov Avatar answered Oct 22 '22 03:10

Ruslan Mansurov


Yep, that's correct.

Under MVVM, the view model should be considered the canonical source of UI data and events (which leads to a whole host of important benefits, like better testability). You'd store the typed NSString on the view model, then bind that to the UI.

With MVC, you'd have to use the controller or model instead, but the principle is the same: treat the view as transient data and do the important stuff elsewhere.

like image 30
Justin Spahr-Summers Avatar answered Oct 22 '22 01:10

Justin Spahr-Summers