Guest User

Untitled

a guest
Oct 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. //
  2. // SettingsViewController.m
  3. // DNA
  4. //
  5. // Created by svp on 28.06.11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9.  
  10.  
  11. #import "SettingsViewController.h"
  12. #import "SwithcerCell.h"
  13. #import "UICustomSwitch.h"
  14. #import "SQLiteAccess.h"
  15. #import "UIViewController+KeyboardMover.h"
  16. #import "DNAAppDelegate.h"
  17. #define COUNTOFALLROWS 6
  18. #define COUNTROWSINFIRSTSECTION 1
  19. #define COUNTROWSINSECONDSECTION 5
  20.  
  21. @implementation SettingsViewController
  22. @synthesize switcherCell;
  23. @synthesize userLabelCell;
  24. @synthesize dataBaseArray;
  25. @synthesize delegate;
  26.  
  27. #pragma mark - NSObject
  28. #pragma mark ---------------------------
  29.  
  30. - (void)dealloc {
  31. [dataBaseArray release];
  32. [userLabelCell release];
  33. [switcherCell release];
  34. [super dealloc];
  35. }
  36.  
  37. - (void)viewDidUnload {
  38. self.userLabelCell=nil;
  39. self.switcherCell=nil;
  40. [super viewDidUnload];
  41. }
  42.  
  43. - (void)viewDidLoad {
  44. NSString *currentCardRequest=@"select * from userSettingsRussian";
  45. NSArray*_dataBaseArray=[SQLiteAccess selectManyRowsWithSQL:currentCardRequest];
  46. self.dataBaseArray=_dataBaseArray;
  47.  
  48. self.title=@"Настройка";
  49. self.navigationItem.hidesBackButton=YES;
  50.  
  51. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"ОК" style:UIBarButtonItemStylePlain target:self action:@selector(okSettings)];
  52. self.navigationItem.rightBarButtonItem = rightButton;
  53. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Отмена" style:UIBarButtonItemStylePlain target:self action:@selector(cancelSettings)];
  54. self.navigationItem.leftBarButtonItem = leftButton;
  55.  
  56. [super viewDidLoad];
  57. }
  58.  
  59. #pragma mark - UITableView
  60. #pragma mark ---------------------------
  61.  
  62. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  63. // There is only one section.
  64. return 2;
  65. }
  66.  
  67.  
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  69. if(section == 0)
  70. return COUNTROWSINFIRSTSECTION;
  71. else
  72. return COUNTROWSINSECONDSECTION;
  73. }
  74.  
  75.  
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  77.  
  78. NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
  79. static NSString *MyIdentifier;
  80. if (indexPath.section ==0)
  81. MyIdentifier= @"SwitchCell";
  82. else
  83. MyIdentifier= @"UserLabel";
  84.  
  85.  
  86. SwithcerCell *cell = (SwithcerCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
  87.  
  88. if (cell == nil) {
  89. [[NSBundle mainBundle] loadNibNamed:@"SwithcerCell" owner:self options:nil];
  90. if (indexPath.section ==0)
  91. {
  92. cell = switcherCell;
  93. self.switcherCell = nil;
  94. }
  95. else
  96. {
  97. cell = userLabelCell;
  98. self.userLabelCell = nil;
  99. }
  100. }
  101.  
  102. if (indexPath.section ==0)
  103. {
  104. [cell.moneySegment setTag:indexPath.row+1];
  105. [cell.moneySegment setSelectedSegmentIndex:[userDefaults boolForKey:@"moneyType"]];
  106. }
  107. else
  108. {
  109. [cell.userInfoTextField setTag:indexPath.row+2];
  110. NSDictionary *currentCard=[dataBaseArray objectAtIndex:indexPath.row];
  111. cell.titleLabel.text=[currentCard objectForKey:@"name"];
  112. cell.userInfoTextField.text=[userDefaults objectForKey:[currentCard objectForKey:@"name"]];
  113.  
  114. }
  115. return cell;
  116. }
  117.  
  118. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
  119. if(section == 0)
  120. return @"Выберите валюту для отображения";
  121. else
  122. return @"Введите ваши данные для удобства";
  123. }
  124. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  125. return nil;
  126. }
  127.  
  128. #pragma mark - Actions
  129. #pragma mark ---------------------------
  130. -(void) okSettings
  131. {
  132. NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
  133. UISegmentedControl *segmentControl=(UISegmentedControl *)[self.view viewWithTag:1];
  134.  
  135. NSLog(@"segmentControl=%i",segmentControl.selectedSegmentIndex);
  136. [userDefaults setBool:segmentControl.selectedSegmentIndex forKey:@"moneyType"];
  137.  
  138. UITextField *currentTextField;
  139. NSDictionary *currentCard;
  140. for (int i=2;i<=COUNTOFALLROWS;i++)
  141. {
  142. currentCard=[dataBaseArray objectAtIndex:i-2];
  143. currentTextField=(UITextField *)[self.view viewWithTag:i];
  144. if ([currentTextField.text length]!=0)
  145. [userDefaults setObject:currentTextField.text forKey:[currentCard objectForKey:@"name"]];
  146. }
  147. [userDefaults synchronize];
  148. DNAAppDelegate*appDelegate=[[UIApplication sharedApplication]delegate];
  149. [appDelegate homeControllerTab];
  150. }
  151. -(void) cancelSettings;
  152. {
  153. DNAAppDelegate*appDelegate=[[UIApplication sharedApplication]delegate];
  154. [appDelegate homeControllerTab];
  155. }
  156.  
  157. #pragma mark - UITextFieldDelegate
  158. #pragma mark ---------------------------
  159.  
  160. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  161. {
  162. [self constructInputAccessoryFor:textField];
  163. return YES;
  164. }
  165.  
  166. - (void)textFieldDidBeginEditing:(UITextField *)textField
  167. {
  168. [self moveViewUp:[textField tag]];
  169. }
  170.  
  171. - (void)textFieldDidEndEditing:(UITextField *)textField
  172. {
  173. [self moveViewDown];
  174. }
  175.  
  176. @end
Add Comment
Please, Sign In to add comment