ios - ReactiveCocoa 两个开关互异绑定怎么写?
PHP中文网
PHP中文网 2017-04-18 09:33:25
0
2
383

假设有两个 Siwtch 需要互异绑定,用 rac 该怎么写?

UISwitch *switch1;
UISwitch *switch2;

switch1.action = {
    switch2.on = !switch2.on;
}

switch2.action = {
    switch1.on = !switch1.on;
}
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
刘奇

Is this so?

switch1.on = YES;
switch2.on = NO;
RACChannelTerminal *t1 = switch1.rac_newOnChannel;
RACChannelTerminal *t2 = switch2.rac_newOnChannel;
[[t1 map:^id(NSNumber *on) {
    return @(![on boolValue]);
}] subscribe:t2];
[[t2 map:^id(NSNumber *on) {
    return @(![on boolValue]);
}] subscribe:t1];
Peter_Zhu

Found a solution:

RACChannelTerminal *aButtonChannel = [aButton rac_newSelectedChannel];
RACChannelTerminal *bButtonChannel = [bButton rac_newSelectedChannel];
[[aButtonChannel not] subscribe:bButtonChannel];
[[bButtonChannel not] subscribe:aButtonChannel];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!