ios - Reactivecocoa绑定(bind)UIButton的标题

标签 ios uibutton reactive-cocoa

RAC(self.balanceLabel,text) = RACObserve(self.viewModel, balance); // balanceLabel is a UILabel,that is ofcourse work
RAC(self.supplierNameButton.titleLabel.text)  = RACObserve(self.viewModel, supplierName); // that is not work,i think this is I don't use the - setTitle:forState: method

我的问题是:我如何使用 Reactivecocoa 将 View 模型的供应商绑定(bind)到其 UIControlStateNormal 的 UIButon 文本

最佳答案

不幸的是,绑定(bind)仅适用于属性,按钮的文本只能使用 setTitle:forState 方法进行更新。

但有一个解决方法:您可以使用 rac_liftSelector:withSignalsFromArray 方法,当您不想弄乱订阅(和 weakify/强化):

[self.supplierNameButtonButton rac_liftSelector:@selector(setTitle:forState:) withSignalsFromArray:@[RACObserve(self.viewModel, supplierName), [RACSignal return:@(UIControlStateNormal)]]];

关于ios - Reactivecocoa绑定(bind)UIButton的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36836717/

相关文章:

ios - ReactiveCocoa 问题

ios - 从 UIDocument 获取单元格数据时,如何确保 UITableView 中显示的列表顺序

ios - 在常规 UIViewController 的 UITableViewCell 中将 UITextField 滚动到键盘上方

ios - 均匀分布 4 或 5 个按钮,具体取决于用户设备

ios - 如果我想为 UIButton 创建更大的点击区域,我应该覆盖 hitTest : or pointInside:?

ios - 使用 ReactiveCocoa 时未调用错误 block

ios - 传递依赖项,包括使用Google Map和集群的静态二进制文件

objective-c - 如何从 NSOperation 获取对 NSOperationQueue 的引用?

ios - UIVIew中的UIButton不在iPhone应用程序中居中

ios - ReactiveCocoa : release a RACSignal when no one subscribes it