Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // IBcells
- //
- // Created by Bogdan Michalchuk on 1/25/15.
- // Copyright (c) 2015 PDXRR. All rights reserved.
- //
- #import "ViewController.h"
- #import "BMOptionCell.h"
- #import "BMSettings.h"
- @interface ViewController ()
- @end
- @implementation ViewController {
- NSArray *tableCellArray;
- BMSettings* settingSetup;
- }
- - (instancetype) initWithCoder:(NSCoder *)aDecoder {
- if (self = [super initWithCoder:aDecoder]) {
- settingSetup = [[BMSettings alloc] init];
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- tableCellArray = [settingSetup getArray];
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- // Assign our own backgroud for the view
- self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
- self.tableView.backgroundColor = [UIColor clearColor];
- [self setSwitch];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- return tableCellArray.count;
- }
- - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
- NSInteger rowIndex = indexPath.row;
- UIImage *background = nil;
- if (rowIndex == 0) {
- background = [UIImage imageNamed:@"cell_top.png"];
- } else if (rowIndex == rowCount - 1) {
- background = [UIImage imageNamed:@"cell_bottom.png"];
- } else {
- background = [UIImage imageNamed:@"cell_middle.png"];
- }
- return background;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- BMOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- cell.cellSwitch.tag = indexPath.row;
- [cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
- // Display setting in the table cell
- BMOptionCell *setting = [tableCellArray objectAtIndex:indexPath.row];
- UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
- settingNameLabel.text = setting.name;
- UISwitch *switchState = (UISwitch *) [cell viewWithTag:102];
- // switchState.state = setting.preferred;
- // Assign our own background image for the cell
- UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
- UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
- cellBackgroundView.image = background;
- cell.backgroundView = cellBackgroundView;
- return cell;
- }
- -(void)switchChanged:(id)sender {
- UISwitch *senderSwitch = (UISwitch *)sender;
- NSUserDefaults *uD = [NSUserDefaults standardUserDefaults];
- if (senderSwitch.tag == 0) {
- if (senderSwitch.on == 1) {
- [uD setObject:@"ON" forKey:@"Call Alert"];
- NSLog(@"Switch 1 ON");
- }
- else if (senderSwitch.on == 0) {
- [uD setObject:@"OFF" forKey:@"Call Alert"];
- NSLog(@"Switch 1 OFF");
- }
- }
- if (senderSwitch.tag == 1) {
- if (senderSwitch.on == 1) {
- [uD setObject:@"ON" forKey:@"AutoPlay"];
- NSLog(@"Switch 2 ON");
- }
- else if (senderSwitch.on == 0) {
- [uD setObject:@"OFF" forKey:@"AutoPlay"];
- NSLog(@"Switch 2 OFF");
- }
- }
- if (senderSwitch.tag == 2) {
- if (senderSwitch.on == 1) {
- [uD setObject:@"ON" forKey:@"Orientation"];
- NSLog(@"Switch 3 ON");
- }
- else if (senderSwitch.on == 0) {
- [uD setObject:@"OFF" forKey:@"Orientation"];
- NSLog(@"Switch 3 OFF");
- }
- }
- [uD synchronize];
- }
- - (void)setSwitch {
- NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
- if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"On"]) {
- // _callConfirmationSwitch.on = YES;
- }
- else if ([[uDefaults stringForKey:@"Call Alert"] isEqualToString:@"Off"]) {
- // _callConfirmationSwitch.on = NO;
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement