diff options
author | Vitaly Takmazov | 2016-08-14 03:27:57 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-08-14 03:27:57 +0300 |
commit | 561df6a1c494bf820c0ed7e3a5b448efd41003f2 (patch) | |
tree | 32533aa0690f7983364e9d31b65135f5b34c3300 /Juick/LoginViewController.m | |
parent | e32c85b7650c0869a2aa319111a837ede75669d1 (diff) |
XLForm
Diffstat (limited to 'Juick/LoginViewController.m')
-rw-r--r-- | Juick/LoginViewController.m | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/Juick/LoginViewController.m b/Juick/LoginViewController.m index a803c48..eedc6d3 100644 --- a/Juick/LoginViewController.m +++ b/Juick/LoginViewController.m @@ -12,9 +12,23 @@ @implementation LoginViewController -static NSString *CellIdentifier = @"CellIdentifier"; +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self){ + [self initializeForm]; + } + return self; +} --(void) viewDidLoad { +- (id)initWithCoder:(NSCoder *)aDecoder { + self = [super initWithCoder:aDecoder]; + if (self){ + [self initializeForm]; + } + return self; +} + +- (void)initializeForm { self.title = @"Sign in"; [self.view setBackgroundColor:[ColorScheme mainBackground]]; @@ -22,8 +36,22 @@ static NSString *CellIdentifier = @"CellIdentifier"; target:self action:@selector(cancelSignIn)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(doneSignIn)]; - [self.usernameField setText:nil]; - [self.passwordField setText:nil]; + XLFormDescriptor *form = [XLFormDescriptor formDescriptorWithTitle:@"Sign in"]; + form.rowNavigationOptions = XLFormRowNavigationOptionEnabled; + XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + XLFormRowDescriptor * usernameRow = [XLFormRowDescriptor + formRowDescriptorWithTag:@"com.juick.username" + rowType:XLFormRowDescriptorTypeText title:@"Username"]; + usernameRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; + [section addFormRow:usernameRow]; + XLFormRowDescriptor * passwordRow = [XLFormRowDescriptor + formRowDescriptorWithTag:@"com.juick.password" + rowType:XLFormRowDescriptorTypePassword title:@"Password"]; + passwordRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; + [section addFormRow:passwordRow]; + + self.form = form; } @@ -54,46 +82,11 @@ static NSString *CellIdentifier = @"CellIdentifier"; } --(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { - NSString *key; - if (textField.tag == 0) { - // username change - key = @"com.juick.username"; - } else { - key = @"com.juick.password"; - } - [[PDKeychainBindings sharedKeychainBindings] setObject:[textField.text stringByReplacingCharactersInRange:range withString:string] forKey:key]; - return YES; -} - -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - return 1; -} - --(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 2; -} - --(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - if (cell == nil) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - } - JVFloatLabeledTextField *textField = [[JVFloatLabeledTextField alloc] init]; - textField.tag = indexPath.row; - textField.delegate = self; - if (indexPath.row == 0) { - textField.floatingLabel.text = @"Username"; - textField.placeholder = @"Username"; - textField.text = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; - } else { - textField.floatingLabel.text = @"Password"; - textField.placeholder = @"Password"; - textField.secureTextEntry = YES; - textField.text = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; +-(void) formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue { + [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue]; + if ([newValue isKindOfClass:[NSString class]]) { + [[PDKeychainBindings sharedKeychainBindings] setObject:newValue forKey:formRow.tag]; } - [cell.contentView addSubview:textField]; - return cell; } @end |