-
Notifications
You must be signed in to change notification settings - Fork 3
/
SettingViewController.m
executable file
·164 lines (149 loc) · 5.4 KB
/
SettingViewController.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// SettingViewController.m
// IWords
//
// Created by yaonphy on 12-11-18.
// Copyright (c) 2012年 yang. All rights reserved.
//
#import "SettingViewController.h"
#import "PreSetViewController.h"
#import "RemindViewController.h"
#import "DownLoadViewController.h"
#import "HelpViewController.h"
#import "ScoreViewController.h"
#import "AboutViewController.h"
#import "FeedbackViewController.h"
#define SET_CELL_FONT [UIFont fontWithName:@"HelveticaNeue-Bold" size:14.00]
@interface SettingViewController ()
{
}
@end
@implementation SettingViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)dealloc
{
[_theDataArr release];
[_theDataDic release];
[_theTableview release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self view]setBackgroundColor:MAIN_BG_COLOR];
self.title = @"设置";
[self initializedData];
[self initializedTableView];
[self.view addSubview:_theTableview];
}
-(void)initializedData
{
NSString * sourcePath = [[NSBundle mainBundle] pathForResource:@"SettingDic" ofType:@"plist"];
_theDataDic = [[NSMutableDictionary alloc]initWithContentsOfFile:sourcePath];
// NSLog(@"%@",_theDataDic);
_theDataArr = [[NSMutableArray alloc]initWithArray:[_theDataDic allKeys]];
}
-(void)initializedTableView
{
_theTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
/* iOS 6 之后模拟器中,Group 类型UITableView 背景颜色设置问题*/
[_theTableview setBackgroundView:nil];
[_theTableview setBackgroundColor:[UIColor clearColor]];
_theTableview.autoresizingMask = UIViewAutoresizingFlexibleHeight;
_theTableview.delegate = self;
[[_theTableview backgroundView] setBackgroundColor:[UIColor clearColor]];
_theTableview.dataSource = self;
[_theTableview setSeparatorColor:[UIColor darkGrayColor]];
[_theTableview setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma UITableView delegate method
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self theDataDic] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[self theDataArr] objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self theDataDic] objectForKey:[[self theDataArr] objectAtIndex:section]] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellID = @"TheCell";
UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSArray * curDataArr = [[self theDataDic] valueForKey:[[self theDataArr] objectAtIndex:indexPath.section]];
[[cell textLabel] setFont:SET_CELL_FONT];
[cell.textLabel setText:[curDataArr objectAtIndex:indexPath.row]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIViewController *theController;
if (indexPath.section == 0) {
theController = [[DownLoadViewController alloc]init];
[self pushDetailViewController:theController];
}
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
theController = [[PreSetViewController alloc]init];;
[self pushDetailViewController:theController];
break;
case 1:
theController = [[RemindViewController alloc]init];
[self pushDetailViewController:theController];
break;
default:
return;
}
}
if (indexPath.section == 2) {
switch (indexPath.row) {
case 0:
theController = [[HelpViewController alloc]init];
[self pushDetailViewController:theController];
break;
case 1:
theController = [[FeedbackViewController alloc]init];
[self pushDetailViewController:theController];
break;
case 2:
theController = [[ScoreViewController alloc]init];
[self pushDetailViewController:theController];
break;
case 3:
theController = [[AboutViewController alloc]init];
[self pushDetailViewController:theController];
break;
default:
return;
}
}
/* theController 在 pushDetailViewController: 方法中 rlease*/
}
-(void)pushDetailViewController:(UIViewController *)theController
{
[self.navigationController pushViewController:theController animated:YES];
[theController release];
}
@end