comparison QuestionnaireViewController.mm @ 21:650589cac373

Picker view stuff started.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 18 Jan 2013 15:48:33 +0000
parents fb2ef16dd013
children 8c0783739337
comparison
equal deleted inserted replaced
20:e44dc6f7f12e 21:650589cac373
7 // 7 //
8 8
9 #import "QuestionnaireViewController.h" 9 #import "QuestionnaireViewController.h"
10 10
11 #include "testApp.h" 11 #include "testApp.h"
12
13 #pragma mark -
14 #pragma mark QuestionnaireViewController
15
12 @interface QuestionnaireViewController () 16 @interface QuestionnaireViewController ()
13 // the "model" is an array of questions and a bunch of answers 17 // the "model" is an array of questions and a bunch of answers
14 @property (strong, nonatomic) NSArray * questionArray; 18 @property (strong, nonatomic) NSArray * questionArray;
15 @property (strong, nonatomic) NSMutableArray * answerArray; 19 @property (strong, nonatomic) NSArray * answerTypeArray;
16 @property (nonatomic) NSInteger currentQuestionIndex; 20 @property (strong, nonatomic) NSMutableArray * answerArray;
17 @property (nonatomic) id theOFAppRef; 21 @property (nonatomic) NSInteger currentQuestionIndex;
22 @property (nonatomic, assign) id theOFAppRef;
23
18 /* 24 /*
19 25
20 26
21 */ 27 */
22 28
23 @end 29 @end
24 30
25 @implementation QuestionnaireViewController 31 @implementation QuestionnaireViewController
26 32
33 @synthesize picker;
34 @synthesize agreeAnswer;
35 @synthesize agreeType;
36 @synthesize answerTypeArray;
27 @synthesize nextButton = _nextButton; 37 @synthesize nextButton = _nextButton;
28 @synthesize segControl = _segControl; 38 @synthesize segControl = _segControl;
29 39
30 //---------------------------------------------------------------- 40 //----------------------------------------------------------------
31 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 41 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
49 { 59 {
50 [super viewDidLoad]; 60 [super viewDidLoad];
51 // Do any additional setup after loading the view from its nib. 61 // Do any additional setup after loading the view from its nib.
52 self.currentQuestionIndex = 0; 62 self.currentQuestionIndex = 0;
53 // load question 1 63 // load question 1
64
65 self.agreeAnswer = [[NSArray alloc] initWithObjects:
66 @"Strongly disagree", @"Disagree", @"Neither",
67 @"Agree", @"Strongly agree", nil];
68
69 self.interfaceAnswer = [[NSArray alloc] initWithObjects:
70 @"Definitely Sliders", @"Maybe Sliders", @"Neither",
71 @"Maybe Zoomer", @"Definitely Zoomer", nil];
72 agreeType = YES;
73
54 [self loadQuestion:self.currentQuestionIndex]; 74 [self loadQuestion:self.currentQuestionIndex];
55 } 75 }
56 //---------------------------------------------------------------- 76 //----------------------------------------------------------------
57 - (void)didReceiveMemoryWarning 77 - (void)didReceiveMemoryWarning
58 { 78 {
117 self.currentQuestionIndex = 0; 137 self.currentQuestionIndex = 0;
118 }else{ 138 }else{
119 [self loadQuestion:self.currentQuestionIndex]; 139 [self loadQuestion:self.currentQuestionIndex];
120 } 140 }
121 } 141 }
122 142 //----------------------------------------------------------------
143
144 // NAH
123 - (IBAction)answerSelected:(id)sender { 145 - (IBAction)answerSelected:(id)sender {
124 // nice short lines of code. 146 // nice short lines of code.
125 147
126 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]]; 148 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
127 149
128 // chek wot we just rote 150 // chek wot we just rote
129 // DUZZNT WERK 151
130 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]); 152 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
131 153
132 154
133 } 155 }
134 //---------------------------------------------------------------- 156 //----------------------------------------------------------------
147 169
148 //---------------------------------------------------------------- 170 //----------------------------------------------------------------
149 - (void)loadQuestion:(NSInteger)questionIndex { 171 - (void)loadQuestion:(NSInteger)questionIndex {
150 // populate text fields with question 172 // populate text fields with question
151 NSString *qtitle; 173 NSString *qtitle;
152 qtitle = [@"Question " stringByAppendingFormat:@"%d",questionIndex+1]; 174 qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
153 self.titleText.text = qtitle; 175 self.titleText.text = qtitle;
154 176
155 self.questionText.text = [self.questionArray objectAtIndex:questionIndex]; 177 self.questionText.text = [self.questionArray objectAtIndex:questionIndex];
156 178
157 // if question already answered show that 179 // if question already answered show that
158 self.segControl.selectedSegmentIndex = (NSInteger)[self.answerArray objectAtIndex:self.currentQuestionIndex]; 180 NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue];
181
182 // set different answer type
183 agreeType = [answerTypeArray objectAtIndex:questionIndex];
184 // then refresh picker view content
185 [picker reloadComponent:0];
186
187
188 // DUZZNT WERK
189 if(answerInt==-1){
190 // select "neither" (2)
191 NSLog(@"No answer answerInt %d", answerInt);
192 [picker selectRow:2 inComponent:0 animated:YES];
193
194 }else{
195 // select previous answer
196 NSLog(@"Prev answer answerInt %d", answerInt);
197 [picker selectRow:answerInt inComponent:0 animated:YES];
198 }
159 } 199 }
160 //---------------------------------------------------------------- 200 //----------------------------------------------------------------
161 - (void)populateQuestionArray{ 201 - (void)populateQuestionArray{
162 self.questionArray = [[NSArray alloc] initWithObjects: 202 self.questionArray = [[NSArray alloc] initWithObjects:
163 @"I am familiar with music software and synthesisers.", 203 @"I am familiar with music software and synthesisers.",
175 @"I felt more in control when using:", 215 @"I felt more in control when using:",
176 @"The Zoomer was an improvement on just using a randomiser.", 216 @"The Zoomer was an improvement on just using a randomiser.",
177 @"The combination of Zoomer and Sliders was more useful than either individually.", 217 @"The combination of Zoomer and Sliders was more useful than either individually.",
178 @"Overall, I preferred using:", 218 @"Overall, I preferred using:",
179 nil]; 219 nil];
220 self.answerTypeArray = [[NSArray alloc] initWithObjects:
221 YES,
222 NO,
223 NO,
224 NO,
225 YES,
226 NO,
227 YES,
228 YES,
229 YES,
230 NO,
231 NO,
232 NO,
233 NO,
234 YES,
235 YES,
236 NO,
237 nil]
180 } 238 }
181 //---------------------------------------------------------------- 239 //----------------------------------------------------------------
182 - (void)populateAnswerArray{ 240 - (void)populateAnswerArray{
183 int N = [self.questionArray count]; 241 int N = [self.questionArray count];
184 242
186 self.answerArray = [[NSMutableArray alloc] initWithCapacity:N]; 244 self.answerArray = [[NSMutableArray alloc] initWithCapacity:N];
187 // set the number to what? 245 // set the number to what?
188 for(int i=0;i<N;i++){ 246 for(int i=0;i<N;i++){
189 [self.answerArray addObject:[NSNumber numberWithInt:-1]]; 247 [self.answerArray addObject:[NSNumber numberWithInt:-1]];
190 } 248 }
191 NSLog(@"Answer count: %d", [self.answerArray count]); 249
192 250 }
251 //----------------------------------------------------------------
252 #pragma mark -
253 #pragma mark PickerView DataSource
254
255 - (NSInteger)numberOfComponentsInPickerView:
256 (UIPickerView *)pickerView
257 {
258 return 1;
259 }
260 - (NSInteger)pickerView:(UIPickerView *)pickerView
261 numberOfRowsInComponent:(NSInteger)component
262 {
263 return [agreeAnswer count]; // always 5
264 }
265 - (NSString *)pickerView:(UIPickerView *)pickerView
266 titleForRow:(NSInteger)row
267 forComponent:(NSInteger)component
268 {
269 if(agreeType){
270 return [agreeAnswer objectAtIndex:row];
271 }else{
272 return [interfaceAnswer objectAtIndex:row];
273 }
274 }
275
276 #pragma mark -
277 #pragma mark PickerView Delegate
278 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
279 inComponent:(NSInteger)component
280 {
281
282 // set question answerArray
283 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:row]];
284
285 // chek wot we just rote
286
287 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
288 /*
289 float rate = [[exchangeRates objectAtIndex:row] floatValue];
290 float dollars = [dollarText.text floatValue];
291 float result = dollars * rate;
292
293 NSString *resultString = [[NSString alloc] initWithFormat:
294 @"%.2f USD = %.2f %@", dollars, result,
295 [countryNames objectAtIndex:row]];
296 resultLabel.text = resultString;
297 */
193 } 298 }
194 299
195 @end // end implementation 300 @end // end implementation
301 //----------------------------------------------------------------
302 //----------------------------------------------------------------