gpt4 book ai didi

ios - 2 RACCommands 以便一个被禁用而另一个正在执行,反之亦然

转载 作者:行者123 更新时间:2023-11-29 11:46:20 25 4
gpt4 key购买 nike

我如何创建 2 个 RACCommand,以便在另一个执行时禁用一个,并且反之亦然

像这样,

_prevTrackCommand = [[RACCommand alloc] initWithEnabled: [_nextTrackCommand.executing not] signalBlock:^RACSignal *(id _) {}];

_nextTrackCommand = [[RACCommand alloc] initWithEnabled: [_prevTrackCommand.executing not] signalBlock:^RACSignal *(id _) {}];

但此代码将不起作用,因为 _nextTrackCommand_prevTrackCommand 初始化时为 nil

最佳答案

您可以使用一个 RACSubject,它可以用作 RACSignal 但允许您手动转发事件:

RACSubject* commandAActive = [RACSubject subject];
RACSubject* commandBActive = [RACSubject subject];

RACCommand* commandA = [[RACCommand alloc] initWithEnabled:[commandBActive not]
signalBlock:^RACSignal * _Nonnull(id _Nullable input) {
// block
}];
RACCommand* commandB = [[RACCommand alloc] initWithEnabled:[commandAActive not]
signalBlock:^RACSignal * _Nonnull(id _Nullable input) {
// block
}];

[commandA.executing subscribeNext:^(NSNumber * _Nullable x) {
[commandAActive sendNext:x];
}];
[commandB.executing subscribeNext:^(NSNumber * _Nullable x) {
[commandBActive sendNext:x];
}];

关于ios - 2 RACCommands 以便一个被禁用而另一个正在执行,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43652352/

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