comparison QuestionnaireViewController.mm @ 43:b91a1859829a

used UIkit sliders
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 19 Apr 2013 18:50:04 +0100
parents a42903c61558
children a1e75b94c505
comparison
equal deleted inserted replaced
42:3d627dce8bf0 43:b91a1859829a
28 28
29 @implementation QuestionnaireViewController 29 @implementation QuestionnaireViewController
30 30
31 @synthesize picker; 31 @synthesize picker;
32 @synthesize nextButton = _nextButton; 32 @synthesize nextButton = _nextButton;
33 @synthesize questionArray; 33 @synthesize questionArray = _questionArray;
34 34
35 35
36 //---------------------------------------------------------------- 36 //----------------------------------------------------------------
37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
38 { 38 {
75 } 75 }
76 //---------------------------------------------------------------- 76 //----------------------------------------------------------------
77 - (void)dealloc { 77 - (void)dealloc {
78 78
79 [_questionText release]; 79 [_questionText release];
80 [_questionArray release];
80 [_titleText release]; 81 [_titleText release];
81 [_finishButton release]; 82 [_finishButton release];
82 [_nextButton release]; 83 [_nextButton release];
83 [_previousButton release]; 84 [_previousButton release];
84 [_commentText release]; 85 [_commentText release];
109 // load answers into a c++ vector; 110 // load answers into a c++ vector;
110 vector<int> answersArray; 111 vector<int> answersArray;
111 112
112 Question *q; 113 Question *q;
113 114
114 for(int i=0;i<[questionArray count];i++){ 115 for(int i=0;i<[self.questionArray count];i++){
115 q = [questionArray objectAtIndex:i]; 116 q = [self.questionArray objectAtIndex:i];
116 answersArray.push_back(q.answer); 117 answersArray.push_back(q.answer);
117 118
118 } 119 }
119 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding]; 120 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
120 [self.commentText resignFirstResponder]; 121 [self.commentText resignFirstResponder];
176 177
177 //---------------------------------------------------------------- 178 //----------------------------------------------------------------
178 - (void)loadQuestion:(NSInteger)questionIndex { 179 - (void)loadQuestion:(NSInteger)questionIndex {
179 // populate text fields with question 180 // populate text fields with question
180 NSString *qtitle; 181 NSString *qtitle;
181 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [questionArray count]]; 182 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [self.questionArray count]];
182 self.titleText.text = qtitle; 183 self.titleText.text = qtitle;
183 184
184 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex]; 185 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
185 186
186 self.questionText.text = curQ.questionText; 187 self.questionText.text = curQ.questionText;
187 188
188 189
189 // refresh picker view content 190 // refresh picker view content
249 //---------------------------------------------------------------- 250 //----------------------------------------------------------------
250 - (NSString *)pickerView:(UIPickerView *)pickerView 251 - (NSString *)pickerView:(UIPickerView *)pickerView
251 titleForRow:(NSInteger)row 252 titleForRow:(NSInteger)row
252 forComponent:(NSInteger)component 253 forComponent:(NSInteger)component
253 { 254 {
254 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex]; 255 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
255 256
256 // get array of answers from Question class 257 // get array of answers from Question class
257 NSArray * answers = [Question answersWithType:curQ.questionType]; 258 NSArray * answers = [Question answersWithType:curQ.questionType];
258 return [answers objectAtIndex:row]; 259 return [answers objectAtIndex:row];
259 260
262 #pragma mark - 263 #pragma mark -
263 #pragma mark PickerView Delegate 264 #pragma mark PickerView Delegate
264 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 265 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
265 inComponent:(NSInteger)component 266 inComponent:(NSInteger)component
266 { 267 {
267 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex]; 268 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
268 // set question answerArray 269 // set question answerArray
269 curQ.answer = row; 270 curQ.answer = row;
270 271
271 // chek wot we just rote 272 // chek wot we just rote
272 273
289 return NO; 290 return NO;
290 } 291 }
291 - (IBAction)answerChosen:(id)sender { 292 - (IBAction)answerChosen:(id)sender {
292 self.pleaseAnswer.hidden = YES; 293 self.pleaseAnswer.hidden = YES;
293 UISegmentedControl *seg = (UISegmentedControl *)sender; 294 UISegmentedControl *seg = (UISegmentedControl *)sender;
294 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex]; 295 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
295 // set question answerArray 296 // set question answerArray
296 curQ.answer = seg.selectedSegmentIndex; 297 curQ.answer = seg.selectedSegmentIndex;
297 298
298 // chek wot we just rote 299 // chek wot we just rote
299 300