ReactiveCocoa / ReactiveObjC

The 2.x ReactiveCocoa Objective-C API: Streams of values over time
MIT License
2.6k stars 493 forks source link

RAC UITextField big bug #21

Open semnyqu opened 7 years ago

semnyqu commented 7 years ago

copy: https://github.com/ReactiveCocoa/ReactiveCocoa/issues/3179#issuecomment-247982879

RACSignal signal1 = self.textField.rac_textSignal; RACSignal cSignal1 = [signal1 distinctUntilChanged]; [cSignal1 subscribeNext:^(NSString *number) {

    NSInteger length = number.length;
    NSString *text = weakself.textField.text;
    DEBUGG(@"111Text: %@, number: %@", text, number);
    if (length >= 20)
    {
        NSString *subText = [number substringToIndex:20];
        DEBUGG(@"subText: %@, number: %@", subText, number);
        weakself.textField.text = subText;
    }
}];

first input text: 1234567891234567 second input text: 12345678912345678; show subtext: 1234567891234567 third input text: 12345678912345678; show subtext: 12345678912345678 because the subscribeNext block is not called;

erikprice commented 7 years ago

I don't really understand the problem you're having, but it sounds like you're saying that

weakself.textField.text = subText;

is not causing the signal to send a new value. This is the expected behavior. -rac_textSignal does not send values in response to calling -[UITextField setText:]. It only sends values in response to user input.