// // LoginViewController.m // Juick // // Created by Vitaly on 30.01.14. // Copyright (c) 2014 com.juick. All rights reserved. // #import "LoginViewController.h" @implementation LoginViewController static NSString *CellIdentifier = @"CellIdentifier"; -(void) viewDidLoad { self.title = @"Sign in"; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelSignIn)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(doneSignIn)]; } - (void) cancelSignIn { CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; transition.subtype = kCATransitionFromTop; [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; [self.navigationController popViewControllerAnimated:NO]; } - (void) doneSignIn { CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; transition.subtype = kCATransitionFromTop; [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; [self.navigationController popToRootViewControllerAnimated:NO]; } -(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"]; } [cell.contentView addSubview:textField]; [textField makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(cell.contentView).with.insets(UIEdgeInsetsMake(5, 25, 5, 25)); }]; return cell; } @end