-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoTableViewController.m
111 lines (80 loc) · 3.07 KB
/
InfoTableViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// InfoTableViewController.m
//
//
// Created by Mladjan Antic on 6/28/15.
//
//
#import "InfoTableViewController.h"
#import "SettingsTableViewCell.h"
@interface InfoTableViewController ()
@end
@implementation InfoTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UILabel *myLabel = [[UILabel alloc] init];
myLabel.frame = footerView.frame;
myLabel.font = [UIFont systemFontOfSize:15];
myLabel.text = @"Version: 1.0";
myLabel.textAlignment = NSTextAlignmentCenter;
myLabel.textColor = [UIColor grayColor];
[footerView addSubview:myLabel];
self.tableView.tableFooterView = footerView;
}
- (IBAction)closeMe:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Table view data source
- (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 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SettingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if(indexPath.row == 0){
cell.label.text = @"Radar control";
cell.rightSwitch.on = [defaults boolForKey:@"radar"];
}else if(indexPath.row == 1){
cell.label.text = @"Alcohol control";
cell.rightSwitch.on = [defaults boolForKey:@"alcohol"];
}else if(indexPath.row == 2){
cell.label.text = @"Regular control";
cell.rightSwitch.on = [defaults boolForKey:@"regular"];
}
cell.rightSwitch.tag = indexPath.row;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 65;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"Notifications";
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *myLabel = [[UILabel alloc] init];
myLabel.frame = CGRectMake(18, 18, 320, 20);
myLabel.font = [UIFont systemFontOfSize:15];
myLabel.text = [self tableView:tableView titleForHeaderInSection:section];
myLabel.textColor = [UIColor grayColor];
UIView *headerView = [[UIView alloc] init];
[headerView addSubview:myLabel];
return headerView;
}
- (IBAction)switchChanged:(UISwitch *)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if(sender.tag == 0){
[defaults setBool:sender.isOn forKey:@"radar"];
}else if(sender.tag == 1){
[defaults setBool:sender.isOn forKey:@"alcohol"];
}else if(sender.tag == 2){
[defaults setBool:sender.isOn forKey:@"regular"];
}
[defaults synchronize];
}
@end