gpt4 book ai didi

ios - ReactiveCocoa takeUntil : doesn't send completion?

转载 作者:行者123 更新时间:2023-11-29 12:39:36 28 4
gpt4 key购买 nike

我正在做一些基本的信号链。按下按钮后,我想等到 loginSignal 完成才能做一些事情。信号完成,但我的 subscribeCompleted: block 没有被调用。

loginSignal 上直接订阅 nextcompletion 会按预期工作。那么,为什么 takeUntil: subscribeCompleted: 不起作用?

[[[button rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:loginSignal] subscribeCompleted:^{
NSLog(@"COMPLETE");
// Do some other stuff
}];

编辑:这是 logAll

的输出
2014-08-15 10:52:56.417 app[88791:60b] <RACDynamicSignal: 0x10c58a120> name:  next: <UIButton: 0x10c68a870; frame = (240 80; 40 40); opaque = NO; autoresize = TM+BM; autoresizesSubviews = NO; tag = 1103; layer = <CALayer: 0x10c6894a0>>
2014-08-15 10:52:56.417 app[88791:60b] <RACDynamicSignal: 0x10c58a120> name: next: <UIButton: 0x10c68a870; frame = (240 80; 40 40); opaque = NO; autoresize = TM+BM; autoresizesSubviews = NO; tag = 1103; layer = <CALayer: 0x10c6894a0>>
2014-08-15 10:53:02.086 app[88791:410b] <RACDynamicSignal: 0x112e2c4b0> name: next: 1
2014-08-15 10:53:02.087 app[88791:410b] <RACDynamicSignal: 0x10c6ea5d0> name: next: 1
2014-08-15 10:53:02.087 app[88791:410b] <RACDynamicSignal: 0x10c6ea5d0> name: next: 1
2014-08-15 10:53:02.088 app[88791:410b] <RACDynamicSignal: 0x10c6b8830> name: next: 1
2014-08-15 10:53:02.089 app[88791:410b] <RACDynamicSignal: 0x10c6b8830> name: next: 1
2014-08-15 10:53:02.089 app[88791:410b] <RACDynamicSignal: 0x10c52e570> name: next: 1
2014-08-15 10:53:02.090 app[88791:410b] <RACDynamicSignal: 0x10c52e570> name: next: 1

编辑 2:这是 loginSignal

RACSignal* loginSignal = [[[RACObserve(obj, loginState) distinctUntilChanged] filter:^BOOL(id value) {
return ([value integerValue] == LOGGEDIN);
}] takeUntil:[self rac_prepareForReuseSignal]];

最佳答案

事实证明,takeUntil: 并不是获得此行为的正确方法。 loginSignal 触发后,它会导致 sendCompleted: 触发多次(因此看起来没有触发?),即使对于尚未点击的按钮也是如此。更好的方法是 flattenMap: 并发送 loginSignal

正确的版本:

[[[[[button rac_signalForControlEvents:UIControlEventTouchUpInside] flattenMap:^RACStream *(id value) {
return loginSignal;
}] take:1] subscribeNext:^(id value){
// DO STUFF!!!
}];

关于ios - ReactiveCocoa takeUntil : doesn't send completion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25330320/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com