The signal you get from -rac_textSignal
only reflects updates from the UI, not programmatic changes like -setText:
.
The simple, imperative fix is to just assign nameIndicator.image
in resetButton
's subscribe block.
[[resetButton
rac_signalForControlEvents:UIControlEventTouchUpInside]
subscribeNext:^(id x) {
username.text = @"";
nameIndicator.image = [UIImage imageNamed:@"RedStar"];
}];
Alternatively, a more functional solution is to create a signal that represents both direct changes to the text field and button taps that clear the text field. The latter signal will sends the empty string when the reset button is tapped, while also clearing the text field.
RACSignal *resetUsernameSignal = [[[resetButton
rac_signalForControlEvents:UIControlEventTouchUpInside]
mapReplace:@""]
doNext:^(NSString *text) {
username.text = text;
}];
RAC(nameIndicator, image) = [[RACSignal
merge:@[
username.rac_textSignal,
resetUsernameSignal
]]
map:^(NSString *text) {
NSLog(@"Text field(username) has been updated: %@", value);
if([value length]) return [UIImage imageNamed:@"GreenStar"];
else return [UIImage imageNamed:@"RedStar"];
}]