Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SettingsViewController.m
- // DNA
- //
- // Created by svp on 28.06.11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "SettingsViewController.h"
- #import "SwithcerCell.h"
- #import "UICustomSwitch.h"
- #import "SQLiteAccess.h"
- #import "UIViewController+KeyboardMover.h"
- #import "DNAAppDelegate.h"
- #define COUNTOFALLROWS 6
- #define COUNTROWSINFIRSTSECTION 1
- #define COUNTROWSINSECONDSECTION 5
- @implementation SettingsViewController
- @synthesize switcherCell;
- @synthesize userLabelCell;
- @synthesize dataBaseArray;
- @synthesize delegate;
- #pragma mark - NSObject
- #pragma mark ---------------------------
- - (void)dealloc {
- [dataBaseArray release];
- [userLabelCell release];
- [switcherCell release];
- [super dealloc];
- }
- - (void)viewDidUnload {
- self.userLabelCell=nil;
- self.switcherCell=nil;
- [super viewDidUnload];
- }
- - (void)viewDidLoad {
- NSString *currentCardRequest=@"select * from userSettingsRussian";
- NSArray*_dataBaseArray=[SQLiteAccess selectManyRowsWithSQL:currentCardRequest];
- self.dataBaseArray=_dataBaseArray;
- self.title=@"Настройка";
- self.navigationItem.hidesBackButton=YES;
- UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"ОК" style:UIBarButtonItemStylePlain target:self action:@selector(okSettings)];
- self.navigationItem.rightBarButtonItem = rightButton;
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Отмена" style:UIBarButtonItemStylePlain target:self action:@selector(cancelSettings)];
- self.navigationItem.leftBarButtonItem = leftButton;
- [super viewDidLoad];
- }
- #pragma mark - UITableView
- #pragma mark ---------------------------
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- // There is only one section.
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if(section == 0)
- return COUNTROWSINFIRSTSECTION;
- else
- return COUNTROWSINSECONDSECTION;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- static NSString *MyIdentifier;
- if (indexPath.section ==0)
- MyIdentifier= @"SwitchCell";
- else
- MyIdentifier= @"UserLabel";
- SwithcerCell *cell = (SwithcerCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
- if (cell == nil) {
- [[NSBundle mainBundle] loadNibNamed:@"SwithcerCell" owner:self options:nil];
- if (indexPath.section ==0)
- {
- cell = switcherCell;
- self.switcherCell = nil;
- }
- else
- {
- cell = userLabelCell;
- self.userLabelCell = nil;
- }
- }
- if (indexPath.section ==0)
- {
- [cell.moneySegment setTag:indexPath.row+1];
- [cell.moneySegment setSelectedSegmentIndex:[userDefaults boolForKey:@"moneyType"]];
- }
- else
- {
- [cell.userInfoTextField setTag:indexPath.row+2];
- NSDictionary *currentCard=[dataBaseArray objectAtIndex:indexPath.row];
- cell.titleLabel.text=[currentCard objectForKey:@"name"];
- cell.userInfoTextField.text=[userDefaults objectForKey:[currentCard objectForKey:@"name"]];
- }
- return cell;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
- if(section == 0)
- return @"Выберите валюту для отображения";
- else
- return @"Введите ваши данные для удобства";
- }
- - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- return nil;
- }
- #pragma mark - Actions
- #pragma mark ---------------------------
- -(void) okSettings
- {
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- UISegmentedControl *segmentControl=(UISegmentedControl *)[self.view viewWithTag:1];
- NSLog(@"segmentControl=%i",segmentControl.selectedSegmentIndex);
- [userDefaults setBool:segmentControl.selectedSegmentIndex forKey:@"moneyType"];
- UITextField *currentTextField;
- NSDictionary *currentCard;
- for (int i=2;i<=COUNTOFALLROWS;i++)
- {
- currentCard=[dataBaseArray objectAtIndex:i-2];
- currentTextField=(UITextField *)[self.view viewWithTag:i];
- if ([currentTextField.text length]!=0)
- [userDefaults setObject:currentTextField.text forKey:[currentCard objectForKey:@"name"]];
- }
- [userDefaults synchronize];
- DNAAppDelegate*appDelegate=[[UIApplication sharedApplication]delegate];
- [appDelegate homeControllerTab];
- }
- -(void) cancelSettings;
- {
- DNAAppDelegate*appDelegate=[[UIApplication sharedApplication]delegate];
- [appDelegate homeControllerTab];
- }
- #pragma mark - UITextFieldDelegate
- #pragma mark ---------------------------
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- {
- [self constructInputAccessoryFor:textField];
- return YES;
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- [self moveViewUp:[textField tag]];
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
- [self moveViewDown];
- }
- @end
Add Comment
Please, Sign In to add comment