Advertisement
Guest User

Untitled

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