redribben

VC

Jan 28th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ViewController.m
  3. //  IBcells
  4. //
  5. //  Created by Bogdan Michalchuk on 1/25/15.
  6. //  Copyright (c) 2015 PDXRR. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "BMOptionCell.h"
  11. #import "BMSettings.h"
  12.  
  13. @interface ViewController ()
  14.  
  15. @end
  16.  
  17. @implementation ViewController {
  18. //    NSArray *settingArray;
  19. }
  20.  
  21. - (void)viewDidLoad {
  22.     [super viewDidLoad];
  23.    
  24.     self.tableView.dataSource = self;
  25.     self.tableView.delegate = self;
  26.  
  27.     // Assign our own backgroud for the view
  28.     self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
  29.     self.tableView.backgroundColor = [UIColor clearColor];
  30.  
  31.     [self setSwitch];
  32.  
  33. }
  34.  
  35. - (void)didReceiveMemoryWarning {
  36.     [super didReceiveMemoryWarning];
  37.     // Dispose of any resources that can be recreated.
  38. }
  39.  
  40. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  41. {
  42.     // Return the number of sections.
  43.     return 1;
  44. }
  45.  
  46.  
  47. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  48. {
  49.     // Return the number of rows in the section.
  50.     return settingArray.count;
  51. }
  52.  
  53. - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
  54. {
  55.     NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
  56.     NSInteger rowIndex = indexPath.row;
  57.     UIImage *background = nil;
  58.    
  59.     if (rowIndex == 0) {
  60.         background = [UIImage imageNamed:@"cell_top.png"];
  61.     } else if (rowIndex == rowCount - 1) {
  62.         background = [UIImage imageNamed:@"cell_bottom.png"];
  63.     } else {
  64.         background = [UIImage imageNamed:@"cell_middle.png"];
  65.     }
  66.    
  67.     return background;
  68. }
  69.  
  70.  
  71. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  72. {
  73.     static NSString *CellIdentifier = @"Cell";
  74.     BMOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  75.    
  76.     cell.cellSwitch.tag = indexPath.row;
  77.    
  78.     [cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  79.    
  80.     // Display setting in the table cell
  81.     BMOptionCell *setting = [settingArray objectAtIndex:indexPath.row];
  82.    
  83.     UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
  84.     settingNameLabel.text = setting.name;
  85.    
  86.     UISwitch *switchState = (UISwitch *) [cell viewWithTag:102];
  87. //    switchState.state = setting.preferred;
  88.  
  89.    
  90.     // Assign our own background image for the cell
  91.     UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
  92.    
  93.     UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
  94.     cellBackgroundView.image = background;
  95.     cell.backgroundView = cellBackgroundView;
  96.    
  97.    
  98.     return cell;
  99. }
  100.  
  101. -(void)switchChanged:(id)sender {
  102.     UISwitch *senderSwitch = (UISwitch *)sender;
  103.     NSUserDefaults *uD = [NSUserDefaults standardUserDefaults];
  104.     if (senderSwitch.tag == 0) {
  105.         if (senderSwitch.on == 1) {
  106.             [uD setObject:@"ON" forKey:@"Call Alert"];
  107.             NSLog(@"Switch 1 ON");
  108.         }
  109.         else if (senderSwitch.on == 0) {
  110.             [uD setObject:@"OFF" forKey:@"Call Alert"];
  111.             NSLog(@"Switch 1 OFF");
  112.         }
  113.     }
  114.     if (senderSwitch.tag == 1) {
  115.         if (senderSwitch.on == 1) {
  116.             [uD setObject:@"ON" forKey:@"AutoPlay"];
  117.             NSLog(@"Switch 2 ON");
  118.         }
  119.         else if (senderSwitch.on == 0) {
  120.             [uD setObject:@"OFF" forKey:@"AutoPlay"];
  121.             NSLog(@"Switch 2 OFF");
  122.         }
  123.     }
  124.     if (senderSwitch.tag == 2) {
  125.         if (senderSwitch.on == 1) {
  126.             [uD setObject:@"ON" forKey:@"Orientation"];
  127.             NSLog(@"Switch 3 ON");
  128.         }
  129.         else if (senderSwitch.on == 0) {
  130.             [uD setObject:@"OFF" forKey:@"Orientation"];
  131.             NSLog(@"Switch 3 OFF");
  132.         }
  133.     }
  134.     [uD synchronize];
  135. }
  136.  
  137.  
  138.  
  139. - (void)setSwitch {
  140.  
  141.     NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
  142.     if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"On"]) {
  143. //        _callConfirmationSwitch.on = YES;
  144.     }
  145.     else if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"Off"]) {
  146. //        _callConfirmationSwitch.on = NO;
  147.     }
  148. }
  149.  
  150. @end
Advertisement
Add Comment
Please, Sign In to add comment