[英]Enabling an UIButton using Reactive Cocoa RACSignal
I have a UIButton
added to a view. 我在视图中添加了一个UIButton
。 My view also has three text box viz. 我的观点还有三个文本框即。 username , password and confirmPassword . 用户名 , 密码和confirmPassword 。 Based on the legitimate content of these text box, I need to enable my signUp button. 根据这些文本框的合法内容,我需要启用我的signUp按钮。
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:- 在最后一行,我遇到两个错误: -
I am new to Reactive Cocoa. 我是Reactive Cocoa的新手。 Please ignore the mistakes. 请忽略错误。
Use RAC(signUp, enabled)
instead of RAC(signUp.enabled)
. 使用RAC(signUp, enabled)
代替RAC(signUp.enabled)
。 The RAC
macro takes at least two arguments, the object and the keypath you are binding. RAC
宏至少使用两个参数,即绑定的对象和keypath。
The RAC()
macro takes two arguments at a minimum, the object that's the target and a valid keypath on that object. RAC()
宏至少接受两个参数,即目标对象和该对象上的有效键路径。
Like so: 像这样:
RAC(signUp, enabled) = formValid;
You're passing it signUp.enabled
, which is a single item, and happens to be a BOOL
, not an object. 你传递的是signUp.enabled
,它是一个单项,恰好是BOOL
,而不是对象。 After the macro is expanded, the BOOL
is passed to a method that expects an object argument, so the compiler complains: 扩展宏之后, BOOL
被传递给期望对象参数的方法,因此编译器会抱怨:
[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:signUp.enabled nilValue:<#garbage#>][@keypath(signUp.enabled, nil)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.