-
Notifications
You must be signed in to change notification settings - Fork 3
/
SetConfirmController.m
executable file
·185 lines (161 loc) · 5.89 KB
/
SetConfirmController.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//
// SetConfirmController.m
// Iwordsv2
//
// Created by yaonphy on 12-10-28.
// Copyright (c) 2012年 yang. All rights reserved.
#import "SetConfirmController.h"
#import "NOIMGButton.h"
#import "RootNavViewController.h"
#import "MainViewController.h"
#import "PreSettingNavController.h"
#define SHOW_ROW 6
#define ROW_HEIHGT 50.0f
#define ROW_BG_COLOR [UIColor colorWithRed:27.0f/RGB_MAX green:24.0f/RGB_MAX blue:24.0f/RGB_MAX alpha:0.8]
#define ROW_BORDER_COLOR [UIColor darkGrayColor]
#define CELL_FONT [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.00]
@interface SetConfirmController ()
{
NSUserDefaults * _theDefault;
}
@end
@implementation SetConfirmController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationItem] setTitle:@"确认计划"];
_showTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width,SHOW_ROW * ROW_HEIHGT) style:UITableViewStylePlain];
_begainButton = [[NOIMGButton alloc]initWithFrame:CGRectMake(32, SHOW_ROW*ROW_HEIHGT+50,256,40) style:NVUIGradientButtonStyleBlackOpaque];
_theDefault = [NSUserDefaults standardUserDefaults];
NSString *plstPath = [[NSBundle mainBundle] pathForResource:@"ConfirmStr" ofType:@"plist"];
_infoStrArr = [[NSArray alloc]initWithContentsOfFile:plstPath];
UITableView * theTableView = [self showTableView];
NOIMGButton * theButton = [self begainButton];
UIView * theView = [self view];
[theButton setText:@"确认设置"];
[theButton addTarget:self action:@selector(nextButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
[theTableView setDelegate:self];
[theTableView setDataSource:self];
[theTableView setBounces:NO];
[theTableView setShowsHorizontalScrollIndicator:NO];
[theTableView setShowsVerticalScrollIndicator:NO];
[theTableView setRowHeight:ROW_HEIHGT];
// [theTableView setBackgroundColor:ROW_BG_COLOR];
[theTableView setSeparatorColor:ROW_BORDER_COLOR];
[theTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[theView addSubview:theTableView];
[theView addSubview:theButton];
theView = nil;
theTableView = nil;
theButton = nil;
}
- (UIWindow *)mainWindow
{
UIApplication *app = [UIApplication sharedApplication];
if ([app.delegate respondsToSelector:@selector(window)])
{
return [app.delegate window];
}
else
{
return [app keyWindow];
}
}
-(void)nextButtonTouched:(UIButton *)sender
{
if ( [[[self navigationController]class] isSubclassOfClass:[PreSettingNavController class]]) {
MainViewController *mainController = [[MainViewController alloc]init];
RootNavViewController * rootNav = [[RootNavViewController alloc]initWithRootViewController:mainController];
[[self mainWindow] setRootViewController:rootNav];
UINavigationController * pareNav = [self navigationController];
[pareNav popViewControllerAnimated:NO];
[pareNav popViewControllerAnimated:NO];
[pareNav release];
[mainController release];
mainController = nil;
[rootNav release];
rootNav = nil;
NSLog(@"第一次");
}else
{
[[self navigationController] popToRootViewControllerAnimated:YES];
NSLog(@"非第一次");
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc
{
_theDefault = nil;
[_infoStrArr release];
[_begainButton release];
[_showTableView release];
[super dealloc];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return SHOW_ROW;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ShowCell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
NSString * theText = [[_infoStrArr objectAtIndex:indexPath.row]copy];
NSString * numStr = nil;
switch (indexPath.row) {
case 0:
numStr = [[NSString alloc]initWithString:[_theDefault valueForKey:@"curLibName"]];
break;
case 1:
numStr = [[NSString alloc]initWithFormat:@"%d",[_theDefault integerForKey:@"NumPerDay"]];
break;
case 2:
numStr = [[NSString alloc]initWithFormat:@"%d",[_theDefault integerForKey:@"ReNumPreDay"]];
break;
case 3:
numStr = [[NSString alloc]initWithFormat:@"%d",[_theDefault integerForKey:@"MaxMeanNum"]];
break;
case 4:
numStr = [[NSString alloc]initWithFormat:@"%d",[_theDefault integerForKey:@"MaxItemNum"]];
break;
case 5:
if ([_theDefault boolForKey:@"IsAutoPlay"]) {
numStr = @" 是";
}else
{
numStr = @" 否";
}
break;
default:
return cell;
}
//如下做法,theText 又指向一个autorelease的新的内存,之前所指向的内存貌似没有释放。
//theText = [theText stringByAppendingString:numStr];
NSString *poitStr = [theText stringByAppendingString:numStr];
[[cell textLabel] setFont:CELL_FONT];
[[cell textLabel] setText:poitStr];
[numStr release];
[theText release];
poitStr = nil;
return cell;
}
@end