使用Reactive Cocoa RACSignal启用UIButton [英] Enabling an UIButton using Reactive Cocoa RACSignal
问题描述
我在视图中添加了 UIButton
。我的观点还有三个文本框即。 用户名,密码和 confirmPassword 。根据这些文本框的合法内容,我需要启用 signUp 按钮。
I have a UIButton
added to a view. My view also has three text box viz. username, password and confirmPassword. Based on the legitimate content of these text box, I need to enable my signUp button.
这是我的代码段: -
Here is my code snippet :-
UIButton *signUp = [[UIButton alloc]initWithFrame:CGRectMake(10, 100, 50, 20)];
signUp.backgroundColor = [UIColor greenColor];
signUp.enabled = NO ;
[self.view addSubview:signUp];
RACSignal *formValid = [RACSignal
combineLatest:@[
username.rac_textSignal,
password.rac_textSignal,
confirmPassword.rac_textSignal
]
reduce:^(NSString *username, NSString *password, NSString *passwordVerification) {
return @([username length] > 0 && [password length] > 8 && [password isEqual:passwordVerification]);
}];
RAC(signUp.enabled) = formValid; //Error is here
在最后一行,我遇到两个错误: -
In the last line, I'm getting two errors:-
- ARC不允许将'BOOL'(又名'signed char')隐式转换为'id'
- 预期标识符
我是Reactive Cocoa的新手。请忽略错误。
I am new to Reactive Cocoa. Please ignore the mistakes.
推荐答案
RAC()
宏需要两个参数至少是目标对象和该对象上的有效密钥路径。
The RAC()
macro takes two arguments at a minimum, the object that's the target and a valid keypath on that object.
如下所示:
RAC(signUp, enabled) = formValid;
你传递的是 signUp.enabled
,这是一个单项,恰好是 BOOL
,而不是对象。扩展宏之后,将 BOOL
传递给期望对象参数的方法,因此编译器会抱怨:
You're passing it signUp.enabled
, which is a single item, and happens to be a BOOL
, not an object. After the macro is expanded, the BOOL
is passed to a method that expects an object argument, so the compiler complains:
[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:signUp.enabled nilValue:<#garbage#>][@keypath(signUp.enabled, nil)]
这篇关于使用Reactive Cocoa RACSignal启用UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!