annotate 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
rev   line source
rt300@16 1 //
rt300@16 2 // QuestionnaireViewController.m
rt300@16 3 // oscSenderExample
rt300@16 4 //
rt300@16 5 // Created by Robert Tubb on 16/01/2013.
rt300@16 6 //
rt300@16 7 //
rt300@16 8
rt300@16 9 #import "QuestionnaireViewController.h"
rt300@16 10
rt300@16 11 #include "testApp.h"
rt300@21 12
rt300@21 13 #pragma mark -
rt300@21 14 #pragma mark QuestionnaireViewController
rt300@21 15
rt300@16 16 @interface QuestionnaireViewController ()
rt300@16 17 // the "model" is an array of questions and a bunch of answers
rt300@21 18 @property (strong, nonatomic) NSArray * questionArray;
rt300@21 19 @property (strong, nonatomic) NSArray * answerTypeArray;
rt300@21 20 @property (strong, nonatomic) NSMutableArray * answerArray;
rt300@21 21 @property (nonatomic) NSInteger currentQuestionIndex;
rt300@21 22 @property (nonatomic, assign) id theOFAppRef;
rt300@21 23
rt300@16 24 /*
rt300@16 25
rt300@16 26
rt300@16 27 */
rt300@16 28
rt300@16 29 @end
rt300@16 30
rt300@16 31 @implementation QuestionnaireViewController
rt300@16 32
rt300@21 33 @synthesize picker;
rt300@21 34 @synthesize agreeAnswer;
rt300@21 35 @synthesize agreeType;
rt300@21 36 @synthesize answerTypeArray;
rt300@16 37 @synthesize nextButton = _nextButton;
rt300@16 38 @synthesize segControl = _segControl;
rt300@16 39
rt300@16 40 //----------------------------------------------------------------
rt300@16 41 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
rt300@16 42 {
rt300@16 43 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
rt300@16 44 if (self) {
rt300@16 45 // Custom initialization
rt300@16 46
rt300@16 47 [self populateQuestionArray ];
rt300@16 48 [self populateAnswerArray];
rt300@16 49
rt300@16 50 }
rt300@16 51 return self;
rt300@16 52 }
rt300@16 53 - (void)setAppRef:(id)theOFApp{
rt300@16 54 self.theOFAppRef = theOFApp;
rt300@16 55
rt300@16 56 }
rt300@16 57 //----------------------------------------------------------------
rt300@16 58 - (void)viewDidLoad
rt300@16 59 {
rt300@16 60 [super viewDidLoad];
rt300@16 61 // Do any additional setup after loading the view from its nib.
rt300@16 62 self.currentQuestionIndex = 0;
rt300@16 63 // load question 1
rt300@21 64
rt300@21 65 self.agreeAnswer = [[NSArray alloc] initWithObjects:
rt300@21 66 @"Strongly disagree", @"Disagree", @"Neither",
rt300@21 67 @"Agree", @"Strongly agree", nil];
rt300@21 68
rt300@21 69 self.interfaceAnswer = [[NSArray alloc] initWithObjects:
rt300@21 70 @"Definitely Sliders", @"Maybe Sliders", @"Neither",
rt300@21 71 @"Maybe Zoomer", @"Definitely Zoomer", nil];
rt300@21 72 agreeType = YES;
rt300@21 73
rt300@16 74 [self loadQuestion:self.currentQuestionIndex];
rt300@16 75 }
rt300@16 76 //----------------------------------------------------------------
rt300@16 77 - (void)didReceiveMemoryWarning
rt300@16 78 {
rt300@16 79 [super didReceiveMemoryWarning];
rt300@16 80 // Dispose of any resources that can be recreated.
rt300@16 81 }
rt300@16 82 //----------------------------------------------------------------
rt300@16 83 - (void)dealloc {
rt300@16 84
rt300@16 85 [_questionText release];
rt300@16 86 [_titleText release];
rt300@16 87 [_finishButton release];
rt300@16 88 [_nextButton release];
rt300@16 89 [_segControl release];
rt300@16 90 [super dealloc];
rt300@16 91 }
rt300@16 92 //----------------------------------------------------------------
rt300@16 93 - (void)viewDidUnload {
rt300@16 94 [self setQuestionText:nil];
rt300@16 95 [self setTitleText:nil];
rt300@16 96 [self setFinishButton:nil];
rt300@16 97 [self setNextButton:nil];
rt300@16 98 [self setSegControl:nil];
rt300@16 99 [super viewDidUnload];
rt300@16 100 }
rt300@16 101 //----------------------------------------------------------------
rt300@16 102 - (IBAction)answerWasSelected:(id)sender {
rt300@16 103 // look at property?
rt300@16 104
rt300@16 105 }
rt300@16 106
rt300@16 107 //----------------------------------------------------------------
rt300@16 108 -(IBAction)hide:(id)sender{
rt300@16 109 // c++ call with NSArray argument??
rt300@16 110 ((testApp *)self.theOFAppRef)->questionnaireHidden(self.answerArray);
rt300@16 111 self.view.hidden = YES;
rt300@16 112 }
rt300@16 113 //----------------------------------------------------------------
rt300@16 114 -(IBAction)show:(id)sender{
rt300@16 115 self.view.hidden = NO;
rt300@16 116 }
rt300@16 117 //----------------------------------------------------------------
rt300@16 118
rt300@16 119 - (IBAction)nextQuestionPressed:(id)sender {
rt300@16 120 // save answer ? no button did that hopefully
rt300@16 121
rt300@16 122 // if last question show thanks
rt300@16 123 // else go to next
rt300@16 124 self.currentQuestionIndex++;
rt300@16 125 if(self.currentQuestionIndex >= [self.questionArray count]){
rt300@16 126 [self showThanks];
rt300@16 127 }else{
rt300@16 128 [self loadQuestion:self.currentQuestionIndex];
rt300@16 129
rt300@16 130 }
rt300@16 131 }
rt300@16 132 //----------------------------------------------------------------
rt300@16 133 - (IBAction)previousQuestionPressed:(id)sender {
rt300@16 134 self.currentQuestionIndex--;
rt300@16 135 if(self.currentQuestionIndex < 0){
rt300@16 136 // nothing
rt300@16 137 self.currentQuestionIndex = 0;
rt300@16 138 }else{
rt300@16 139 [self loadQuestion:self.currentQuestionIndex];
rt300@16 140 }
rt300@16 141 }
rt300@21 142 //----------------------------------------------------------------
rt300@16 143
rt300@21 144 // NAH
rt300@16 145 - (IBAction)answerSelected:(id)sender {
rt300@16 146 // nice short lines of code.
rt300@16 147
rt300@16 148 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
rt300@16 149
rt300@16 150 // chek wot we just rote
rt300@21 151
rt300@16 152 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
rt300@16 153
rt300@16 154
rt300@16 155 }
rt300@16 156 //----------------------------------------------------------------
rt300@16 157
rt300@16 158 - (void)showThanks{
rt300@16 159 // hide next question button
rt300@16 160 self.nextButton.hidden = YES;
rt300@16 161 // hide selector
rt300@16 162 self.segControl.hidden = YES;
rt300@16 163
rt300@16 164
rt300@16 165 self.titleText.text = @"Thank you!";
rt300@16 166
rt300@16 167 self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events.";
rt300@16 168 }
rt300@16 169
rt300@16 170 //----------------------------------------------------------------
rt300@16 171 - (void)loadQuestion:(NSInteger)questionIndex {
rt300@16 172 // populate text fields with question
rt300@16 173 NSString *qtitle;
rt300@21 174 qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
rt300@16 175 self.titleText.text = qtitle;
rt300@16 176
rt300@16 177 self.questionText.text = [self.questionArray objectAtIndex:questionIndex];
rt300@16 178
rt300@16 179 // if question already answered show that
rt300@21 180 NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue];
rt300@21 181
rt300@21 182 // set different answer type
rt300@21 183 agreeType = [answerTypeArray objectAtIndex:questionIndex];
rt300@21 184 // then refresh picker view content
rt300@21 185 [picker reloadComponent:0];
rt300@21 186
rt300@21 187
rt300@21 188 // DUZZNT WERK
rt300@21 189 if(answerInt==-1){
rt300@21 190 // select "neither" (2)
rt300@21 191 NSLog(@"No answer answerInt %d", answerInt);
rt300@21 192 [picker selectRow:2 inComponent:0 animated:YES];
rt300@21 193
rt300@21 194 }else{
rt300@21 195 // select previous answer
rt300@21 196 NSLog(@"Prev answer answerInt %d", answerInt);
rt300@21 197 [picker selectRow:answerInt inComponent:0 animated:YES];
rt300@21 198 }
rt300@16 199 }
rt300@16 200 //----------------------------------------------------------------
rt300@16 201 - (void)populateQuestionArray{
rt300@16 202 self.questionArray = [[NSArray alloc] initWithObjects:
rt300@16 203 @"I am familiar with music software and synthesisers.",
rt300@16 204 @"The best way to get a feel for the possibilities of the synth was with:",
rt300@16 205 @"Interesting sounds could be discovered more quickly as a result of using:",
rt300@16 206 @"A sound could be fine tuned more easily using:",
rt300@16 207 @"The correspondence between the sliders and the grid was understandable.",
rt300@16 208 @"The interface that felt more familiar was:",
rt300@16 209 @"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.",
rt300@16 210 @"The ability to see other presets on the grid was useful.",
rt300@16 211 @"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.",
rt300@16 212 @"The interface better for generating new ideas was",
rt300@16 213 @"The interface better for live performance would be:",
rt300@16 214 @"A specific type of sound could be found more quickly using:",
rt300@16 215 @"I felt more in control when using:",
rt300@16 216 @"The Zoomer was an improvement on just using a randomiser.",
rt300@16 217 @"The combination of Zoomer and Sliders was more useful than either individually.",
rt300@16 218 @"Overall, I preferred using:",
rt300@16 219 nil];
rt300@21 220 self.answerTypeArray = [[NSArray alloc] initWithObjects:
rt300@21 221 YES,
rt300@21 222 NO,
rt300@21 223 NO,
rt300@21 224 NO,
rt300@21 225 YES,
rt300@21 226 NO,
rt300@21 227 YES,
rt300@21 228 YES,
rt300@21 229 YES,
rt300@21 230 NO,
rt300@21 231 NO,
rt300@21 232 NO,
rt300@21 233 NO,
rt300@21 234 YES,
rt300@21 235 YES,
rt300@21 236 NO,
rt300@21 237 nil]
rt300@16 238 }
rt300@16 239 //----------------------------------------------------------------
rt300@16 240 - (void)populateAnswerArray{
rt300@16 241 int N = [self.questionArray count];
rt300@16 242
rt300@16 243 //[self.answerArray initWithCapacity:N]; // necessary?
rt300@16 244 self.answerArray = [[NSMutableArray alloc] initWithCapacity:N];
rt300@16 245 // set the number to what?
rt300@16 246 for(int i=0;i<N;i++){
rt300@16 247 [self.answerArray addObject:[NSNumber numberWithInt:-1]];
rt300@16 248 }
rt300@16 249
rt300@16 250 }
rt300@21 251 //----------------------------------------------------------------
rt300@21 252 #pragma mark -
rt300@21 253 #pragma mark PickerView DataSource
rt300@16 254
rt300@21 255 - (NSInteger)numberOfComponentsInPickerView:
rt300@21 256 (UIPickerView *)pickerView
rt300@21 257 {
rt300@21 258 return 1;
rt300@21 259 }
rt300@21 260 - (NSInteger)pickerView:(UIPickerView *)pickerView
rt300@21 261 numberOfRowsInComponent:(NSInteger)component
rt300@21 262 {
rt300@21 263 return [agreeAnswer count]; // always 5
rt300@21 264 }
rt300@21 265 - (NSString *)pickerView:(UIPickerView *)pickerView
rt300@21 266 titleForRow:(NSInteger)row
rt300@21 267 forComponent:(NSInteger)component
rt300@21 268 {
rt300@21 269 if(agreeType){
rt300@21 270 return [agreeAnswer objectAtIndex:row];
rt300@21 271 }else{
rt300@21 272 return [interfaceAnswer objectAtIndex:row];
rt300@21 273 }
rt300@21 274 }
rt300@21 275
rt300@21 276 #pragma mark -
rt300@21 277 #pragma mark PickerView Delegate
rt300@21 278 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
rt300@21 279 inComponent:(NSInteger)component
rt300@21 280 {
rt300@21 281
rt300@21 282 // set question answerArray
rt300@21 283 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:row]];
rt300@21 284
rt300@21 285 // chek wot we just rote
rt300@21 286
rt300@21 287 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
rt300@21 288 /*
rt300@21 289 float rate = [[exchangeRates objectAtIndex:row] floatValue];
rt300@21 290 float dollars = [dollarText.text floatValue];
rt300@21 291 float result = dollars * rate;
rt300@21 292
rt300@21 293 NSString *resultString = [[NSString alloc] initWithFormat:
rt300@21 294 @"%.2f USD = %.2f %@", dollars, result,
rt300@21 295 [countryNames objectAtIndex:row]];
rt300@21 296 resultLabel.text = resultString;
rt300@21 297 */
rt300@21 298 }
rt300@21 299
rt300@21 300 @end // end implementation
rt300@21 301 //----------------------------------------------------------------
rt300@21 302 //----------------------------------------------------------------