From 561df6a1c494bf820c0ed7e3a5b448efd41003f2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 14 Aug 2016 03:27:57 +0300 Subject: XLForm --- Juick/LoginViewController.h | 7 +--- Juick/LoginViewController.m | 79 ++++++++++++++++++--------------------- Juick/RevealPanelViewController.m | 2 +- 3 files changed, 39 insertions(+), 49 deletions(-) (limited to 'Juick') diff --git a/Juick/LoginViewController.h b/Juick/LoginViewController.h index 9ebf187..bf980fa 100644 --- a/Juick/LoginViewController.h +++ b/Juick/LoginViewController.h @@ -7,12 +7,9 @@ // #import -#import "JVFloatLabeledTextField.h" +#import "XLForm.h" #import "PDKeychainbindingsController.h" -@interface LoginViewController : UITableViewController - -@property(nonatomic, strong) JVFloatLabeledTextField *usernameField; -@property(nonatomic, strong) JVFloatLabeledTextField *passwordField; +@interface LoginViewController : XLFormViewController @end 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 diff --git a/Juick/RevealPanelViewController.m b/Juick/RevealPanelViewController.m index b79ceff..1e9fb7b 100644 --- a/Juick/RevealPanelViewController.m +++ b/Juick/RevealPanelViewController.m @@ -145,7 +145,7 @@ static NSString *CellIdentifier = @"NavCell"; - (void) pushLoginForm { [self.revealViewController revealToggle:self]; - UIViewController *loginView = [[LoginViewController alloc] initWithStyle:UITableViewStyleGrouped]; + UIViewController *loginView = [[LoginViewController alloc] init]; UINavigationController *messages = (UINavigationController *)self.revealViewController.frontViewController; [messages pushViewController:loginView animated:YES]; } -- cgit v1.2.3