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/