【问题标题】:ReactiveCocoa `rac_textSignal` map completed eventReactiveCocoa `rac_textSignal` 映射完成事件
【发布时间】:2016-02-09 17:38:33
【问题描述】:

我是 Reactive Cocoa 的新手。

当空白被添加到UITextView 时,我需要触发一些东西, 用修剪后的版本替换文本视图文本。所以基本上我正在寻找某种完成事件。我想这是一件简单的事情,但我一定错过了一些重要的东西......这就是我所拥有的:

RACSignal *whitespaceSignal = [self.field.rac_textSignal filter:^BOOL(NSString *input) {
    return [self textContainsWhitespace:input];
}];

RAC(self.field, text) = [whitespaceSignal map:^id(NSString *input) {
    // The stuff that needs to happen *after* the text field has 
    // got the new, trimmed value.. But here it gets triggered before 
    // the UITextView updates its value.
    // [self respondToWhiteSpaceTrimmedEvent];
    return [self trimWhitespace:input];
}];

我尝试了subscribeCompletedthencompleted 块的几种组合,但没有一个被调用。

如何检测self.field.text 何时更新其值以响应whitespaceSignal,然后才触发我的副作用?

【问题讨论】:

  • 您在map 之后尝试过doNext 吗?您应该在 doNext 中收到更新的“修剪”值,并且您可以响应 doNext 块内的修剪事件值
  • @Nimble 谢谢,不幸的是这也没有被调用。
  • 更正,doNext 实际上确实被调用了,但是如果 UITextView 的文本到那时还没有更新(实际上没有),那对我来说毫无用处。 doComplete 没有被调用。
  • 请解释一下您到底想实现什么,也许可以使用 Reactive Cocoa 的不同功能来完成

标签: ios objective-c uitextview reactive-cocoa racsignal


【解决方案1】:

您是否订阅过您创建的信号?您过滤/映射信号,但很明显您没有订阅信号,所以我认为这就是原因。

[[self.field.rac_textSignal map:^id(NSString *input) {
    // The stuff that needs to happen *after* the text field has 
    // got the new, trimmed value.. But here it gets triggered before 
    // the UITextView updates its value.
    // [self respondToWhiteSpaceTrimmedEvent];
    return [self trimWhitespace:input];
}] subscribeNext:^(id x) {
    // Do some stuff after you replace whitespace ...
}];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2018-03-27
    • 1970-01-01
    相关资源
    最近更新 更多