redribben

progress

Jan 29th, 2015
258
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 *tableCellArray;
  19.     BMSettings* settingSetup;
  20.     NSString* cellRow;
  21. }
  22.  
  23. - (instancetype) initWithCoder:(NSCoder *)aDecoder {
  24.     if (self = [super initWithCoder:aDecoder]) {
  25.         settingSetup = [[BMSettings alloc] init];
  26.     }
  27.     return self;
  28. }
  29.  
  30. - (void)viewDidLoad {
  31.     [super viewDidLoad];
  32.    
  33.     tableCellArray =  [settingSetup getArray];
  34.    
  35.     self.tableView.dataSource = self;
  36.     self.tableView.delegate = self;
  37.  
  38.     // Assign our own backgroud for the view
  39.     self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
  40.     self.tableView.backgroundColor = [UIColor clearColor];
  41.  
  42.     [self setSwitch];
  43.  
  44. }
  45.  
  46. - (void)didReceiveMemoryWarning {
  47.     [super didReceiveMemoryWarning];
  48.     // Dispose of any resources that can be recreated.
  49. }
  50.  
  51. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  52. {
  53.     // Return the number of sections.
  54.     return 1;
  55. }
  56.  
  57.  
  58. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  59. {
  60.     // Return the number of rows in the section.
  61.     return tableCellArray.count;
  62. }
  63.  
  64. - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66.     NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
  67.     NSInteger rowIndex = indexPath.row;
  68.     UIImage *background = nil;
  69.    
  70.     if (rowIndex == 0) {
  71.         background = [UIImage imageNamed:@"cell_top.png"];
  72.     } else if (rowIndex == rowCount - 1) {
  73.         background = [UIImage imageNamed:@"cell_bottom.png"];
  74.     } else {
  75.         background = [UIImage imageNamed:@"cell_middle.png"];
  76.     }
  77.    
  78.     return background;
  79. }
  80.  
  81.  
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84.     static NSString *CellIdentifier = @"Cell";
  85.     BMOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  86.    
  87.     cell.cellSwitch.tag = indexPath.row;
  88.    
  89.    
  90. //    cellRow.tag = indexPath.row;
  91. //    cell.cellSwitch.name = indexPath.row;
  92. //    i = indexPath.row;
  93. //    cellRow =[(BMSettings *)[tableCellArray objectAtIndex:[cell.cellSwitch.tag]] UDKey]
  94.    
  95.     cell.cellSwitch.([(BMSettings *)[tableCellArray objectAtIndex:[cell.cellSwitch.tag]] UDKey]);
  96.    
  97.    
  98.    
  99.    
  100.    
  101.     [cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  102.    
  103.     // Display setting in the table cell
  104.     BMOptionCell *setting = [tableCellArray objectAtIndex:indexPath.row];
  105.    
  106.     UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
  107.     settingNameLabel.text = setting.name;
  108.    
  109.     UISwitch *switchState = (UISwitch *) [cell viewWithTag:102];
  110. //    switchState.state = setting.preferred;
  111.  
  112.    
  113.     // Assign our own background image for the cell
  114.     UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
  115.    
  116.     UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
  117.     cellBackgroundView.image = background;
  118.     cell.backgroundView = cellBackgroundView;
  119.    
  120.    
  121.     return cell;
  122. }
  123.  
  124. -(void)switchChanged:(id)sender {
  125.     UISwitch *senderSwitch = (UISwitch *)sender;
  126.     NSUserDefaults *uD = [NSUserDefaults standardUserDefaults];
  127.     if (senderSwitch.tag == 0) {
  128.         if (senderSwitch.on == 1) {
  129.             [uD setObject:@"ON" forKey:@"Call Alert"];
  130.             NSLog(@"Switch 1 ON");
  131.         }
  132.         else if (senderSwitch.on == 0) {
  133.             [uD setObject:@"OFF" forKey:@"Call Alert"];
  134.             NSLog(@"Switch 1 OFF");
  135.         }
  136.     }
  137.     if (senderSwitch.tag == 1) {
  138.         if (senderSwitch.on == 1) {
  139.             [uD setObject:@"ON" forKey:@"AutoPlay"];
  140.             NSLog(@"Switch 2 ON");
  141.         }
  142.         else if (senderSwitch.on == 0) {
  143.             [uD setObject:@"OFF" forKey:@"AutoPlay"];
  144.             NSLog(@"Switch 2 OFF");
  145.         }
  146.     }
  147.     if (senderSwitch.tag == 2) {
  148.         if (senderSwitch.on == 1) {
  149.             [uD setObject:@"ON" forKey:@"Orientation"];
  150.             NSLog(@"Switch 3 ON");
  151.         }
  152.         else if (senderSwitch.on == 0) {
  153.             [uD setObject:@"OFF" forKey:@"Orientation"];
  154.             NSLog(@"Switch 3 OFF");
  155.         }
  156.     }
  157.     [uD synchronize];
  158. }
  159.  
  160.  
  161.  
  162. - (void)setSwitch {
  163.  
  164.     NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
  165.     if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"On"]) {
  166. //        _callConfirmationSwitch.on = YES;
  167.     }
  168.     else if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"Off"]) {
  169. //        _callConfirmationSwitch.on = NO;
  170.     }
  171. }
  172.  
  173. @end
Advertisement
Add Comment
Please, Sign In to add comment