Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  SpecificViewController.m
  3. //  SettingsNavigationView
  4. //
  5. //  Created by Pawel Nuzka on 7/26/11.
  6. //  Copyright 2011 PWR. All rights reserved.
  7. //
  8.  
  9. #import "SpecificViewController.h"
  10.  
  11.  
  12. @implementation SpecificViewController
  13. @synthesize data;
  14. @synthesize ID;
  15. - (id)initWithStyle:(UITableViewStyle)style
  16. {
  17.     self = [super initWithStyle:style];
  18.     if (self) {
  19.         // Custom initialization
  20.     }
  21.     return self;
  22. }
  23.  
  24. - (void)dealloc
  25. {
  26.     [super dealloc];
  27. }
  28.  
  29. - (void)didReceiveMemoryWarning
  30. {
  31.     // Releases the view if it doesn't have a superview.
  32.     [super didReceiveMemoryWarning];
  33.    
  34.     // Release any cached data, images, etc that aren't in use.
  35. }
  36.  
  37. #pragma mark - View lifecycle
  38.  
  39. - (void)viewDidLoad
  40. {
  41.     [super viewDidLoad];
  42.  
  43.     // Uncomment the following line to preserve selection between presentations.
  44.     // self.clearsSelectionOnViewWillAppear = NO;
  45.  
  46.     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  47.     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  48. }
  49.  
  50. - (void)viewDidUnload
  51. {
  52.     [super viewDidUnload];
  53.     // Release any retained subviews of the main view.
  54.     // e.g. self.myOutlet = nil;
  55. }
  56.  
  57. - (void)viewWillAppear:(BOOL)animated
  58. {
  59.     [super viewWillAppear:animated];
  60. }
  61.  
  62. - (void)viewDidAppear:(BOOL)animated
  63. {
  64.     [super viewDidAppear:animated];
  65. }
  66.  
  67. - (void)viewWillDisappear:(BOOL)animated
  68. {
  69.     [super viewWillDisappear:animated];
  70. }
  71.  
  72. - (void)viewDidDisappear:(BOOL)animated
  73. {
  74.     [super viewDidDisappear:animated];
  75. }
  76.  
  77. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  78. {
  79.     // Return YES for supported orientations
  80.     return YES;
  81. }
  82.  
  83. #pragma mark - Table view data source
  84.  
  85. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  86. {
  87.     // Return the number of sections.
  88.     return 1;
  89. }
  90.  
  91. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  92. {
  93.     // Return the number of rows in the section.
  94.     return [data count];
  95. }
  96.  
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99.     static NSString *CellIdentifier = @"Cell";
  100.    
  101.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  102.     if (cell == nil) {
  103.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  104.     }
  105.     CGRect frame = cell.frame;
  106.     frame.origin.x += 20;
  107.     UITextField *textField = [[UITextField alloc] initWithFrame:frame];
  108.     [textField setDelegate:self];
  109.     if (indexPath.row == 0)
  110.         [textField setPlaceholder:@"login"];
  111.     else
  112.     {
  113.         [textField setPlaceholder:@"password"];
  114.         [textField setSecureTextEntry:YES];
  115.     }
  116.     [textField setTag:indexPath.row];
  117.     [textField setText:[data objectAtIndex:indexPath.row]];
  118.     [cell addSubview:textField];
  119.     return cell;
  120. }
  121. - (void)textFieldDidEndEditing:(UITextField *)textField
  122. {
  123.     NSString *value = [data objectAtIndex:textField.tag];
  124.     value = textField.text;
  125.     NSMutableArray *settings = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"settings"]];
  126.     NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[settings objectAtIndex:[self.ID intValue]]];
  127.     if (textField.tag == 0)
  128.         [dict setObject:value forKey:@"login"];
  129.     else
  130.         [dict setObject:value forKey:@"password"];
  131.     [settings replaceObjectAtIndex:[self.ID intValue] withObject:dict];
  132.     [[NSUserDefaults standardUserDefaults] setObject:settings forKey:@"settings"];
  133.     NSLog(@"userDef%@", settings);
  134.     NSLog(@"value %@", value);
  135. }
  136. /*
  137. // Override to support conditional editing of the table view.
  138. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  139. {
  140.     // Return NO if you do not want the specified item to be editable.
  141.     return YES;
  142. }
  143. */
  144.  
  145. /*
  146. // Override to support editing the table view.
  147. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  148. {
  149.     if (editingStyle == UITableViewCellEditingStyleDelete) {
  150.         // Delete the row from the data source
  151.         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  152.     }  
  153.     else if (editingStyle == UITableViewCellEditingStyleInsert) {
  154.         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  155.     }  
  156. }
  157. */
  158.  
  159. /*
  160. // Override to support rearranging the table view.
  161. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  162. {
  163. }
  164. */
  165.  
  166. /*
  167. // Override to support conditional rearranging of the table view.
  168. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  169. {
  170.     // Return NO if you do not want the item to be re-orderable.
  171.     return YES;
  172. }
  173. */
  174.  
  175. #pragma mark - Table view delegate
  176.  
  177. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  178. {
  179.     // Navigation logic may go here. Create and push another view controller.
  180.     /*
  181.      <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
  182.      // ...
  183.      // Pass the selected object to the new view controller.
  184.      [self.navigationController pushViewController:detailViewController animated:YES];
  185.      [detailViewController release];
  186.      */
  187. }
  188.  
  189. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement