2

我是 Reactive Cocoa 的新手。

在将文本视图文本替换为修剪后的版本,我需要在将空白添加到 a 时触发内容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];
}];

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

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

4

1 回答 1

0

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

[[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 ...
}];
于 2016-02-22T16:15:16.290 回答