2016-02-09 38 views
2

我是Reactive Cocoa的新手。ReactiveCocoa`rac_textSignal` map completed event

我需要在白色空間被添加到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,然後才觸發我的副作用?

+0

你在'map'之後試過'doNext'嗎?你應該在doNext中收到更新後的「trimmed」值,你可以迴應doNext塊內的修剪事件值 – Nimble

+0

@Nimble謝謝,不幸的是這也沒有被調用。 – Elise

+0

更正,'doNext'實際上被調用,但如果'UITextView'的文本在那一點還沒有更新(並且不是),那麼對我來說它是沒用的。 'doComplete'不會被調用。 – Elise

回答

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 ... 
}];