Skip to content

Instantly share code, notes, and snippets.

@iComputerfreak
Last active August 29, 2015 14:01
Show Gist options
  • Save iComputerfreak/fa3d3ee925c45cd6e1f2 to your computer and use it in GitHub Desktop.
Save iComputerfreak/fa3d3ee925c45cd6e1f2 to your computer and use it in GitHub Desktop.
SettingsViewController
//
// SettingsViewController.h
// HFG Vertretungsplan
//
// Created by Jonas Frey on 13.05.14.
// Copyright (c) 2014 Jonas Frey. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SettingsViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIPickerView *elementPicker;
@property (nonatomic, strong) NSMutableArray *elements;
- (IBAction)userOrPasswordChanged:(id)sender;
@end
//
// SettingsViewController.m
// HFG Vertretungsplan
//
// Created by Jonas Frey on 13.05.14.
// Copyright (c) 2014 Jonas Frey. All rights reserved.
//
#import "SettingsViewController.h"
#import "NSData+CommonCrypto.h"
#import "JFUtils.h"
#import "SVProgressHUD.h"
@interface SettingsViewController ()
@end
@implementation SettingsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.elements = [NSMutableArray arrayWithObjects:@"Object 1", @"Object 2", @"Object 3", nil];
NSLog(@"%@", self.elements);
[self loadContent];
}
- (void)loadContent {
NSData *passwordData = [[NSUserDefaults standardUserDefaults] objectForKey:JFSettingsKeyPassword];
NSError *error = nil;
self.passwordTextField.text = [[NSString alloc] initWithData:[passwordData decryptedAES256DataUsingKey:@"Password" error:&error] encoding:NSUTF8StringEncoding];
if (error) {
NSLog(@"Error encrypting password: \n%@", error);
[SVProgressHUD showErrorWithStatus:@"Fehler beim Laden der Anmeldeinformationen"];
passwordData = nil;
return;
}
self.userTextField.text = [[NSUserDefaults standardUserDefaults] objectForKey:JFSettingsKeyUser];
passwordData = nil;
}
- (IBAction)userOrPasswordChanged:(id)sender {...}
- (void)viewWillDisappear:(BOOL)animated {...}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[[NSUserDefaults standardUserDefaults] setObject:[self.elements objectAtIndex:row] forKey:JFSettingsKeyElement];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
NSLog(@"numberOfComponentsInPickerView: %@", self.elements);
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.elements count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.elements objectAtIndex:row];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment