Skip to content
Permalink
Browse files

use textfield event (observer text property)

  • Loading branch information...
HarrisonXi committed Aug 15, 2018
1 parent 0feb1cb commit ad46b53d99920a377de01a4da4f95c44022ef896
Showing with 10 additions and 3 deletions.
  1. +10 −3 MvvmDemo/ViewController.m
@@ -21,13 +21,20 @@ - (void)viewDidLoad {
[super viewDidLoad];

self.viewModel = [ViewModel new];
// bind input signals
EZR_PATH(self.viewModel, username) = EZR_PATH(self.usernameTextField, text);
EZR_PATH(self.viewModel, password) = EZR_PATH(self.passwordTextField, text);
// bind output signals
EZR_PATH(self.usernameTextField, backgroundColor) = ConvertInputStateToColor(EZR_PATH(self.viewModel, usernameInputState));
EZR_PATH(self.passwordTextField, backgroundColor) = ConvertInputStateToColor(EZR_PATH(self.viewModel, passwordInputState));
EZR_PATH(self.loginButton, enabled) = EZR_PATH(self.viewModel, loginEnabled);
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(nonnull NSString *)string
{
if (textField == self.usernameTextField) {
self.viewModel.username = [textField.text stringByReplacingCharactersInRange:range withString:string];
} else {
self.viewModel.password = [textField.text stringByReplacingCharactersInRange:range withString:string];
}
return YES;
}

@end

0 comments on commit ad46b53

Please sign in to comment.
You can’t perform that action at this time.