1 | #import "PrefTable.h"
|
---|
2 |
|
---|
3 | @implementation PrefTable
|
---|
4 | - (id)initWithFrame:(CGRect)rect {
|
---|
5 | if ((self == [ super initWithFrame: rect ]) != nil) {
|
---|
6 | int i, j;
|
---|
7 |
|
---|
8 | for(i=0;i<NUM_GROUPS;i++) {
|
---|
9 | groupcell[i] = NULL;
|
---|
10 | for(j=0;j<CELLS_PER_GROUP;j++)
|
---|
11 | cells[i][j] = NULL;
|
---|
12 | }
|
---|
13 |
|
---|
14 | [ self setDataSource: self ];
|
---|
15 | [ self setDelegate: self ];
|
---|
16 | }
|
---|
17 |
|
---|
18 | return self;
|
---|
19 | }
|
---|
20 |
|
---|
21 | - (int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)aTable {
|
---|
22 |
|
---|
23 | /* Number of logical groups, including labels */
|
---|
24 | return NUM_GROUPS;
|
---|
25 | }
|
---|
26 |
|
---|
27 | - (int)preferencesTable:(UIPreferencesTable *)aTable
|
---|
28 | numberOfRowsInGroup:(int)group
|
---|
29 | {
|
---|
30 | switch (group) {
|
---|
31 | case 0:
|
---|
32 | return 1;
|
---|
33 | break;
|
---|
34 | case 1:
|
---|
35 | return 2;
|
---|
36 | break;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | - (UIPreferencesTableCell *)preferencesTable:
|
---|
41 | (UIPreferencesTable *)aTable
|
---|
42 | cellForGroup:(int)group
|
---|
43 | {
|
---|
44 | if (groupcell[group] != NULL)
|
---|
45 | return groupcell[group];
|
---|
46 |
|
---|
47 | groupcell[group] = [ [ UIPreferencesTableCell alloc ] init ];
|
---|
48 | switch (group) {
|
---|
49 | case 0:
|
---|
50 | [ groupcell[group] setTitle: @"Presentation" ];
|
---|
51 | break;
|
---|
52 | case 1:
|
---|
53 | [ groupcell[group] setTitle: @"Search" ];
|
---|
54 | break;
|
---|
55 | }
|
---|
56 | return groupcell[group];
|
---|
57 | }
|
---|
58 |
|
---|
59 | - (float)preferencesTable:(UIPreferencesTable *)aTable
|
---|
60 | heightForRow:(int)row
|
---|
61 | inGroup:(int)group
|
---|
62 | withProposedHeight:(float)proposed
|
---|
63 | {
|
---|
64 | /* Return height for group titles */
|
---|
65 | if (row == -1) {
|
---|
66 | if (group < 2)
|
---|
67 | return 40;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (group == 0 && row == 0) {
|
---|
71 | return 55.0;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | return proposed;
|
---|
76 | }
|
---|
77 |
|
---|
78 | - (BOOL)preferencesTable:(UIPreferencesTable *)aTable
|
---|
79 | isLabelGroup:(int)group
|
---|
80 | {
|
---|
81 | return NO;
|
---|
82 | }
|
---|
83 |
|
---|
84 | -(UIPreferencesTableCell*) preferencesTable:
|
---|
85 | (UIPreferencesTable *)aTable
|
---|
86 | cellForRow:(int)row
|
---|
87 | inGroup:(int)group
|
---|
88 | {
|
---|
89 | UIPreferencesTableCell *cell;
|
---|
90 |
|
---|
91 | if (cells[group][row] != NULL)
|
---|
92 | return cells[group][row];
|
---|
93 |
|
---|
94 | cell = [ [ UIPreferencesTableCell alloc ] init ];
|
---|
95 | [ cell setEnabled: YES ];
|
---|
96 |
|
---|
97 | switch (group) {
|
---|
98 | case (0):
|
---|
99 | switch (row) {
|
---|
100 | case (0):
|
---|
101 | [ cell setTitle:@"Language" ];
|
---|
102 | langControl = [ [ UISegmentedControl alloc ]
|
---|
103 | initWithFrame:CGRectMake(170, 5, 135, 50)
|
---|
104 | ];
|
---|
105 | [ langControl insertSegment:0
|
---|
106 | withTitle:@"English" animated: NO ];
|
---|
107 | [ langControl insertSegment:1
|
---|
108 | withTitle:@"French" animated: NO ];
|
---|
109 | [ langControl selectSegment: 0 ];
|
---|
110 | [ cell addSubview: langControl ];
|
---|
111 | break;
|
---|
112 | }
|
---|
113 | break;
|
---|
114 | case (1):
|
---|
115 | switch (row) {
|
---|
116 | case (0):
|
---|
117 | [ cell setTitle:@"Stemming" ];
|
---|
118 | stemmingControl = [ [ UISwitchControl alloc ]
|
---|
119 | initWithFrame:CGRectMake(170, 5, 120, 55)
|
---|
120 | ];
|
---|
121 | [ stemmingControl setValue: 0.0 ];
|
---|
122 | [ cell addSubview: stemmingControl ];
|
---|
123 | break;
|
---|
124 | case (1):
|
---|
125 | [ cell setTitle:@"Case matching" ];
|
---|
126 | caseControl = [ [ UISwitchControl alloc ]
|
---|
127 | initWithFrame:CGRectMake(170, 5, 120, 30)
|
---|
128 | ];
|
---|
129 | [ caseControl setValue: 0.0 ];
|
---|
130 | [ caseControl setAlternateColors: NO ];
|
---|
131 | [ cell addSubview: caseControl ];
|
---|
132 | break;
|
---|
133 | case (2):
|
---|
134 | [ cell setTitle:@"Case matching" ];
|
---|
135 | caseControl = [ [ UISwitchControl alloc ]
|
---|
136 | initWithFrame:CGRectMake(170, 5, 120, 30)
|
---|
137 | ];
|
---|
138 | [ caseControl setValue: 0.0 ];
|
---|
139 | [ caseControl setAlternateColors: NO ];
|
---|
140 | [ cell addSubview: caseControl ];
|
---|
141 | break;
|
---|
142 | }
|
---|
143 | break;
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | [ cell setShowSelection: NO ];
|
---|
148 | cells[group][row] = cell;
|
---|
149 | return cell;
|
---|
150 | }
|
---|
151 |
|
---|
152 | -(NSString*) languagePref
|
---|
153 | {
|
---|
154 | NSString* lang = [NSString alloc];
|
---|
155 |
|
---|
156 | if (langControl.selectedSegment==0) {
|
---|
157 | lang = [lang initWithString:@"en"];
|
---|
158 | }
|
---|
159 | else {
|
---|
160 | lang = [lang initWithString:@"fr"];
|
---|
161 | }
|
---|
162 |
|
---|
163 | return lang;
|
---|
164 | }
|
---|
165 |
|
---|
166 | @end
|
---|