redribben

tags

Jan 28th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2. #import "BMOptionCell.h"
  3.  
  4. @interface ViewController ()
  5.  
  6. @end
  7.  
  8. @implementation ViewController {
  9.     NSArray *settingArray;
  10. }
  11.  
  12. //-(id)init {
  13. //    self = [super init];
  14. //    if (self) {
  15. //        //self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
  16. //        //self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  17. //        self.tableView.dataSource = self;
  18. //        self.tableView.delegate = self;
  19. //        //self.tableView.scrollEnabled = NO;
  20. //        //self.tableView.layer.cornerRadius = PanelCornerRadius;
  21. //        //[self addSubview:self.tableView];
  22. //    }
  23. //    return self;
  24. //}
  25.  
  26. - (void)viewDidLoad {
  27.     [super viewDidLoad];
  28.    
  29.     self.tableView.dataSource = self;
  30.     self.tableView.delegate = self;
  31.    
  32.     // Create settings array
  33.     BMOptionCell *setting1 = [BMOptionCell new];
  34.     setting1.name = @"Live Call Confirmation";
  35.     setting1.detail = @"An alert pops up and asks if you are sure that you would like to make to the studio";
  36.     setting1.setOn = @"There will be a pop up that confirms that you really do wish to make the call";
  37.     setting1.setOff = @"The call will go through right away";
  38.  
  39.    
  40.     BMOptionCell *setting2 = [BMOptionCell new];
  41.     setting2.name = @"Play On Launch";
  42.     setting2.detail = @"The option to have Radio automatically start playing when the application launches";
  43.     setting2.setOn = @"The radio will start playing when the application launches";
  44.     setting2.setOff = @"The play button will need to have to be clicked for the audio to start playing";
  45.  
  46.    
  47.     BMOptionCell *setting3 = [BMOptionCell new];
  48.     setting3.name = @"Allow Landscape Orientation";
  49.     setting3.detail = @"Enables the applications to be used in all orientations";
  50.     setting3.setOn = @"The application could be used when the device is sideways";
  51.     setting3.setOff = @"The application will only work in portrait style";
  52.    
  53.  
  54.    
  55.     settingArray = [NSArray arrayWithObjects:setting1, setting2, setting3, nil];
  56.  
  57.     // Assign our own backgroud for the view
  58.     self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
  59.     self.tableView.backgroundColor = [UIColor clearColor];
  60.  
  61.     [self setSwitch];
  62.  
  63. }
  64.  
  65. - (void)didReceiveMemoryWarning {
  66.     [super didReceiveMemoryWarning];
  67.     // Dispose of any resources that can be recreated.
  68. }
  69.  
  70. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  71. {
  72.     // Return the number of sections.
  73.     return 1;
  74. }
  75.  
  76.  
  77. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  78. {
  79.     // Return the number of rows in the section.
  80.     return settingArray.count;
  81. }
  82.  
  83. - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
  84. {
  85.     NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
  86.     NSInteger rowIndex = indexPath.row;
  87.     UIImage *background = nil;
  88.    
  89.     if (rowIndex == 0) {
  90.         background = [UIImage imageNamed:@"cell_top.png"];
  91.     } else if (rowIndex == rowCount - 1) {
  92.         background = [UIImage imageNamed:@"cell_bottom.png"];
  93.     } else {
  94.         background = [UIImage imageNamed:@"cell_middle.png"];
  95.     }
  96.    
  97.     return background;
  98. }
  99.  
  100.  
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103.     static NSString *CellIdentifier = @"Cell";
  104.     BMOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  105.    
  106.     cell.cellSwitch.tag = indexPath.row;
  107.    
  108.     [cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  109.    
  110.     // Configure the cell...
  111.     if (cell == nil) {
  112.         cell = [[BMOptionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  113.     }
  114.    
  115.     // Display recipe in the table cell
  116.     BMOptionCell *setting = [settingArray objectAtIndex:indexPath.row];
  117.    
  118.     UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
  119.     settingNameLabel.text = setting.name;
  120.    
  121.     UISwitch *switchState = (UISwitch *) [cell viewWithTag:102];
  122. //    switchState.state = setting.preferred;
  123.  
  124.    
  125.     // Assign our own background image for the cell
  126.     UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
  127.    
  128.     UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
  129.     cellBackgroundView.image = background;
  130.     cell.backgroundView = cellBackgroundView;
  131.    
  132.    
  133.     return cell;
  134. }
  135.  
  136. -(void)switchChanged:(id)sender {
  137.     UISwitch *senderSwitch = (UISwitch *)sender;
  138.     NSUserDefaults *uD = [NSUserDefaults standardUserDefaults];
  139.     if (senderSwitch.tag == 0) {
  140.         if (senderSwitch.on == 1) {
  141.             [uD setObject:@"ON" forKey:@"Call Alert"];
  142.             NSLog(@"Switch 1 ON");
  143.         }
  144.         else if (senderSwitch.on == 0) {
  145.             [uD setObject:@"OFF" forKey:@"Call Alert"];
  146.             NSLog(@"Switch 1 OFF");
  147.         }
  148.     }
  149.     if (senderSwitch.tag == 1) {
  150.         if (senderSwitch.on == 1) {
  151.             [uD setObject:@"ON" forKey:@"AutoPlay"];
  152.             NSLog(@"Switch 2 ON");
  153.         }
  154.         else if (senderSwitch.on == 0) {
  155.             [uD setObject:@"OFF" forKey:@"AutoPlay"];
  156.             NSLog(@"Switch 2 OFF");
  157.         }
  158.     }
  159.     if (senderSwitch.tag == 2) {
  160.         if (senderSwitch.on == 1) {
  161.             [uD setObject:@"ON" forKey:@"Orientation"];
  162.             NSLog(@"Switch 3 ON");
  163.         }
  164.         else if (senderSwitch.on == 0) {
  165.             [uD setObject:@"OFF" forKey:@"Orientation"];
  166.             NSLog(@"Switch 3 OFF");
  167.         }
  168.     }
  169.     [uD synchronize];
  170. }
  171.  
  172.  
  173.  
  174. - (void)setSwitch {
  175.  
  176.     NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
  177.     if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"On"]) {
  178. //        _callConfirmationSwitch.on = YES;
  179.     }
  180.     else if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"Off"]) {
  181. //        _callConfirmationSwitch.on = NO;
  182.     }
  183. }
  184.  
  185. @end
Advertisement
Add Comment
Please, Sign In to add comment