1 |
|
---|
2 | #import "PrefViewController.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | @implementation PrefViewController
|
---|
6 |
|
---|
7 | - (id) init {
|
---|
8 | self = [ super initWithStyle: UITableViewStyleGrouped ];
|
---|
9 |
|
---|
10 | if (self != nil) {
|
---|
11 | self.title = @"Preferences";
|
---|
12 | }
|
---|
13 | return self;
|
---|
14 | }
|
---|
15 |
|
---|
16 | /*
|
---|
17 | // The designated initializer. Override to perform setup that is required before the view is loaded.
|
---|
18 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
---|
19 | if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
|
---|
20 | // Custom initialization
|
---|
21 | }
|
---|
22 | return self;
|
---|
23 | }
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | // Implement loadView to create a view hierarchy programmatically, without using a nib.
|
---|
28 | - (void)loadView {
|
---|
29 | [super loadView];
|
---|
30 | }
|
---|
31 |
|
---|
32 | /*
|
---|
33 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
|
---|
34 | - (void)viewDidLoad {
|
---|
35 | [super viewDidLoad];
|
---|
36 | }
|
---|
37 | */
|
---|
38 |
|
---|
39 |
|
---|
40 | /*
|
---|
41 | // Override to allow orientations other than the default portrait orientation.
|
---|
42 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
---|
43 | // Return YES for supported orientations
|
---|
44 | return (interfaceOrientation == UIInterfaceOrientationPortrait);
|
---|
45 | }
|
---|
46 | */
|
---|
47 | /*
|
---|
48 | - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
|
---|
49 | LogMethod();
|
---|
50 | switch (interfaceOrientation) {
|
---|
51 | case UIInterfaceOrientationPortrait:
|
---|
52 | {
|
---|
53 | }
|
---|
54 | break;
|
---|
55 |
|
---|
56 | case UIInterfaceOrientationLandscapeRight:
|
---|
57 | {
|
---|
58 | }
|
---|
59 | break;
|
---|
60 |
|
---|
61 | case UIInterfaceOrientationLandscapeRight:
|
---|
62 | {
|
---|
63 | }
|
---|
64 | break;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
---|
69 | LogMethod();
|
---|
70 | }
|
---|
71 | */
|
---|
72 |
|
---|
73 | - (void)didReceiveMemoryWarning {
|
---|
74 | // Releases the view if it doesn't have a superview.
|
---|
75 | [super didReceiveMemoryWarning];
|
---|
76 |
|
---|
77 | // Release any cached data, images, etc that aren't in use.
|
---|
78 | }
|
---|
79 |
|
---|
80 | - (void)viewDidUnload {
|
---|
81 | // Release any retained subviews of the main view.
|
---|
82 | // e.g. self.myOutlet = nil;
|
---|
83 | activeTextField = nil;
|
---|
84 | }
|
---|
85 |
|
---|
86 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
---|
87 |
|
---|
88 | /* Number of logical groups, including labels ?!?*/
|
---|
89 | return PREF_NUM_GROUPS;
|
---|
90 | }
|
---|
91 |
|
---|
92 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
---|
93 | {
|
---|
94 | switch (section) {
|
---|
95 | case(0):
|
---|
96 | return 1;
|
---|
97 | break;
|
---|
98 | case(1):
|
---|
99 | return 2;
|
---|
100 | break;
|
---|
101 | }
|
---|
102 |
|
---|
103 | return 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
---|
107 | {
|
---|
108 | switch (section) {
|
---|
109 | case(0):
|
---|
110 | return @"Presentation";
|
---|
111 | break;
|
---|
112 | case(1):
|
---|
113 | return @"Search";
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | return nil;
|
---|
117 | }
|
---|
118 |
|
---|
119 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
---|
120 | {
|
---|
121 | NSString *CellIdentifier = [ NSString stringWithFormat: @"%d:%d", [ indexPath indexAtPosition: 0 ], [ indexPath indexAtPosition:1 ]];
|
---|
122 |
|
---|
123 | UITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier];
|
---|
124 |
|
---|
125 | if (cell == nil) {
|
---|
126 | cell = [ [ [ UITableViewCell alloc ] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease ];
|
---|
127 |
|
---|
128 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
---|
129 |
|
---|
130 | switch ([ indexPath indexAtPosition: 0]) {
|
---|
131 | case(0):
|
---|
132 | switch([ indexPath indexAtPosition: 1]) {
|
---|
133 | case(0):
|
---|
134 | {
|
---|
135 | UISegmentedControl *langControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: @"English", @"French", @"German", nil]];
|
---|
136 | langControl.contentMode = UIViewContentModeScaleToFill;
|
---|
137 | langControl.frame = CGRectMake(145, 5, 150, 35);
|
---|
138 | langControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
|
---|
139 | langControl.selectedSegmentIndex = 0;
|
---|
140 | langControl.tag = 3;
|
---|
141 | [langControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
|
---|
142 | langControl.segmentedControlStyle = UISegmentedControlStyleBar;
|
---|
143 |
|
---|
144 | [cell addSubview:langControl];
|
---|
145 | cell.textLabel.text = @"Language";
|
---|
146 | [langControl release];
|
---|
147 | }
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | break;
|
---|
151 | case(1):
|
---|
152 | switch ([ indexPath indexAtPosition: 1 ]) {
|
---|
153 | case(0):
|
---|
154 | {
|
---|
155 | UISwitch *stemmingControl = [ [ UISwitch alloc ] initWithFrame: CGRectMake(200, 10, 60, 30) ];
|
---|
156 | stemmingControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
|
---|
157 | stemmingControl.on = YES;
|
---|
158 | stemmingControl.tag = 1;
|
---|
159 | [stemmingControl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
|
---|
160 | [ cell addSubview: stemmingControl ];
|
---|
161 | cell.textLabel.text = @"Stemming";
|
---|
162 | [stemmingControl release];
|
---|
163 | }
|
---|
164 | break;
|
---|
165 | case(1):
|
---|
166 | {
|
---|
167 | UISwitch *casematchControl = [ [ UISwitch alloc ] initWithFrame: CGRectMake(200, 10, 50, 30) ];
|
---|
168 | casematchControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
|
---|
169 | casematchControl.on = NO;
|
---|
170 | casematchControl.tag = 2;
|
---|
171 | [casematchControl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
|
---|
172 | [ cell addSubview: casematchControl ];
|
---|
173 | cell.textLabel.text = @"Case matching";
|
---|
174 | [casematchControl release];
|
---|
175 | }
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | break;
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | return cell;
|
---|
183 | }
|
---|
184 |
|
---|
185 | #pragma mark ControlEventTarget Actions
|
---|
186 |
|
---|
187 |
|
---|
188 | - (void)segmentAction:(UISegmentedControl*)sender
|
---|
189 | {
|
---|
190 | if ([activeTextField canResignFirstResponder])
|
---|
191 | [activeTextField resignFirstResponder];
|
---|
192 |
|
---|
193 | DEBUGLOG(NSLog(@"segmentAction: sender = %d, segment = %d", [sender tag], [sender selectedSegmentIndex]));
|
---|
194 | }
|
---|
195 |
|
---|
196 | - (void)switchAction:(UISwitch*)sender
|
---|
197 | {
|
---|
198 | if ([activeTextField canResignFirstResponder])
|
---|
199 | [activeTextField resignFirstResponder];
|
---|
200 | DEBUGLOG(NSLog(@"switchAction: sender = %d, isOn %d", [sender tag], [sender isOn]));
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | - (void)dealloc {
|
---|
205 | [activeTextField release];
|
---|
206 | [super dealloc];
|
---|
207 | }
|
---|
208 |
|
---|
209 | @end
|
---|