redribben icon

tags

redribben | PRO | 01/28/15 04:53:35 PM UTC | 0 ⭐ | 403 👁️ | Never ⏰ | []
Objective C |

0 B

|

None

|

0 👍

/

0 👎

#import "ViewController.h"
#import "BMOptionCell.h"
 
@interface ViewController ()
 
@end
 
@implementation ViewController {
    NSArray *settingArray;
}
 
//-(id)init {
//    self = [super init];
//    if (self) {
//        //self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
//        //self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//        self.tableView.dataSource = self;
//        self.tableView.delegate = self;
//        //self.tableView.scrollEnabled = NO;
//        //self.tableView.layer.cornerRadius = PanelCornerRadius;
//        //[self addSubview:self.tableView];
//    }
//    return self;
//}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    // Create settings array
    BMOptionCell *setting1 = [BMOptionCell new];
    setting1.name = @"Live Call Confirmation";
    setting1.detail = @"An alert pops up and asks if you are sure that you would like to make to the studio";
    setting1.setOn = @"There will be a pop up that confirms that you really do wish to make the call";
    setting1.setOff = @"The call will go through right away";
 
    
    BMOptionCell *setting2 = [BMOptionCell new];
    setting2.name = @"Play On Launch";
    setting2.detail = @"The option to have Radio automatically start playing when the application launches";
    setting2.setOn = @"The radio will start playing when the application launches";
    setting2.setOff = @"The play button will need to have to be clicked for the audio to start playing";
 
    
    BMOptionCell *setting3 = [BMOptionCell new];
    setting3.name = @"Allow Landscape Orientation";
    setting3.detail = @"Enables the applications to be used in all orientations";
    setting3.setOn = @"The application could be used when the device is sideways";
    setting3.setOff = @"The application will only work in portrait style";
    
 
    
    settingArray = [NSArray arrayWithObjects:setting1, setting2, setting3, nil];
 
    // 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 settingArray.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];
    
    // Configure the cell...
    if (cell == nil) {
        cell = [[BMOptionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    // Display recipe in the table cell
    BMOptionCell *setting = [settingArray 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

Comments