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

送分小仙女□ 提交于 2019-12-05 05:19:10

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.

Just send action:

[self.inputTextView sendActionsForControlEvents:UIControlEventEditingChanged];

The following is a workaround that works:

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

Thanks to startupthekid on GitHub.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!