annotate QuestionnaireViewController.mm @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents 27cdf475aa4b
children
rev   line source
rt300@0 1 //
rt300@0 2 // QuestionnaireViewController.m
rt300@0 3 // oscSenderExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 16/01/2013.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #import "QuestionnaireViewController.h"
rt300@0 10
rt300@0 11 #include "testApp.h"
rt300@0 12
rt300@0 13 #pragma mark -
rt300@0 14 #pragma mark QuestionnaireViewController
rt300@0 15
rt300@0 16 @interface QuestionnaireViewController ()
rt300@0 17 // the "model" is an array of questions
rt300@0 18 @property (strong, nonatomic) NSArray * questionArray;
rt300@0 19 @property (nonatomic) NSInteger currentQuestionIndex;
rt300@0 20 @property (nonatomic, assign) id theOFAppRef;
rt300@27 21 @property (nonatomic) NSInteger interfaceSelection;
rt300@0 22 /*
rt300@0 23
rt300@0 24
rt300@0 25 */
rt300@0 26
rt300@0 27 @end
rt300@0 28
rt300@0 29 @implementation QuestionnaireViewController
rt300@0 30
rt300@0 31 @synthesize picker;
rt300@0 32 @synthesize nextButton = _nextButton;
rt300@0 33 @synthesize questionArray = _questionArray;
rt300@0 34
rt300@0 35
rt300@0 36 //----------------------------------------------------------------
rt300@0 37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
rt300@0 38 {
rt300@0 39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
rt300@0 40 if (self) {
rt300@0 41 // Custom initialization
rt300@0 42
rt300@0 43 [self populateQuestionArray ];
rt300@0 44
rt300@27 45 self.interfaceSelection = 0;
rt300@0 46 }
rt300@0 47 return self;
rt300@0 48 }
rt300@0 49 - (void)setAppRef:(id)theOFApp{
rt300@0 50 self.theOFAppRef = theOFApp;
rt300@0 51
rt300@0 52 }
rt300@0 53 //----------------------------------------------------------------
rt300@0 54 - (void)viewDidLoad
rt300@0 55 {
rt300@0 56 [super viewDidLoad];
rt300@0 57 // Do any additional setup after loading the view from its nib.
rt300@0 58 self.currentQuestionIndex = 0;
rt300@0 59
rt300@0 60 // load question 1
rt300@0 61 [self loadQuestion:self.currentQuestionIndex];
rt300@0 62
rt300@0 63 self.previousButton.hidden = NO; // bother
rt300@0 64 self.commentText.hidden = YES;
rt300@0 65 self.finishButton.hidden = YES;
rt300@0 66 self.nextButton.hidden = YES;
rt300@0 67
rt300@0 68 self.lickertOptions.hidden = NO;
rt300@0 69 self.interfacePreferenceOptions.hidden = YES;
rt300@0 70 }
rt300@0 71 //----------------------------------------------------------------
rt300@0 72 - (void)didReceiveMemoryWarning
rt300@0 73 {
rt300@0 74 [super didReceiveMemoryWarning];
rt300@0 75 // Dispose of any resources that can be recreated.
rt300@0 76 }
rt300@0 77 //----------------------------------------------------------------
rt300@0 78 - (void)dealloc {
rt300@0 79
rt300@0 80 [super dealloc];
rt300@0 81 }
rt300@0 82 //----------------------------------------------------------------
rt300@0 83 - (void)viewDidUnload {
rt300@0 84 [self.questionArray release];
rt300@0 85 [self setQuestionText:nil];
rt300@0 86 [self setTitleText:nil];
rt300@0 87 [self setFinishButton:nil];
rt300@0 88 [self setNextButton:nil];
rt300@0 89 [self setPreviousButton:nil];
rt300@0 90 [self setCommentText:nil];
rt300@0 91 [self setNumberChooser:nil];
rt300@0 92 [self setInterfacePreferenceOptions:nil];
rt300@0 93 [self setLickertOptions:nil];
rt300@0 94 [self setPleaseAnswer:nil];
rt300@0 95 [super viewDidUnload];
rt300@0 96 }
rt300@0 97 //----------------------------------------------------------------
rt300@0 98 -(IBAction)hide:(id)sender{
rt300@0 99 // called when finish button hit
rt300@0 100 // c++ call with NSArray argument??
rt300@0 101 // load answers into a c++ vector;
rt300@0 102 vector<int> answersArray;
rt300@0 103
rt300@0 104 Question *q;
rt300@0 105
rt300@0 106 for(int i=0;i<[self.questionArray count];i++){
rt300@0 107 q = [self.questionArray objectAtIndex:i];
rt300@0 108 answersArray.push_back(q.answer);
rt300@0 109
rt300@0 110 }
rt300@0 111 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
rt300@0 112 [self.commentText resignFirstResponder];
rt300@0 113
rt300@0 114 self.view.hidden = YES;
rt300@0 115 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray, userComments);
rt300@0 116
rt300@0 117 }
rt300@0 118
rt300@0 119 //----------------------------------------------------------------
rt300@0 120 -(IBAction)show:(id)sender{
rt300@0 121 self.view.hidden = NO;
rt300@0 122 }
rt300@0 123 //----------------------------------------------------------------
rt300@0 124
rt300@0 125 - (IBAction)nextQuestionPressed:(id)sender {
rt300@0 126 // save answer ? no button did that hopefully
rt300@0 127
rt300@0 128 // if last question show thanks
rt300@0 129 // else go to next
rt300@0 130 self.currentQuestionIndex++;
rt300@0 131 if(self.currentQuestionIndex >= [self.questionArray count]){
rt300@0 132 [self showThanks];
rt300@0 133 }else{
rt300@0 134 [self loadQuestion:self.currentQuestionIndex];
rt300@0 135
rt300@0 136 }
rt300@0 137 }
rt300@0 138 //----------------------------------------------------------------
rt300@0 139 - (IBAction)previousQuestionPressed:(id)sender {
rt300@0 140 self.currentQuestionIndex--;
rt300@0 141 if(self.currentQuestionIndex < 0){
rt300@0 142 // nothing
rt300@0 143 self.currentQuestionIndex = 0;
rt300@0 144 }else{
rt300@0 145 [self loadQuestion:self.currentQuestionIndex];
rt300@0 146 }
rt300@0 147 }
rt300@0 148
rt300@0 149 //----------------------------------------------------------------
rt300@0 150
rt300@0 151 - (void)showThanks{
rt300@0 152 // hide next question button
rt300@0 153 self.nextButton.hidden = YES;
rt300@0 154 // hide selector
rt300@0 155 self.picker.hidden = YES;
rt300@0 156 self.previousButton.hidden = YES;
rt300@0 157 self.finishButton.hidden = NO;
rt300@0 158
rt300@0 159 self.lickertOptions.hidden = YES;
rt300@0 160 self.interfacePreferenceOptions.hidden = YES;
rt300@0 161
rt300@0 162 self.titleText.text = @"Thank you!";
rt300@0 163 self.numberChooser.hidden = YES;
rt300@0 164 self.commentText.hidden = NO;
rt300@0 165
rt300@0 166 self.questionText.text = @"Thanks for helping science help you. Feel free to add further comments in the text box below, and then press 'finish' to go back and use the app.";
rt300@0 167 }
rt300@0 168
rt300@0 169 //----------------------------------------------------------------
rt300@0 170 - (void)loadQuestion:(NSInteger)questionIndex {
rt300@0 171 // populate text fields with question
rt300@0 172 NSString *qtitle;
rt300@0 173 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [self.questionArray count]];
rt300@0 174 self.titleText.text = qtitle;
rt300@0 175
rt300@0 176 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
rt300@0 177
rt300@0 178 self.questionText.text = curQ.questionText;
rt300@0 179
rt300@0 180
rt300@0 181 // refresh picker view content
rt300@0 182 //[picker reloadComponent:0];
rt300@0 183
rt300@0 184 // show correct option number labels
rt300@0 185 if(curQ.questionType == AGREE_DISAGREE){
rt300@0 186 self.lickertOptions.hidden = NO;
rt300@0 187 self.interfacePreferenceOptions.hidden = YES;
rt300@0 188 }else if(curQ.questionType == SLIDERS_ZOOMER){
rt300@0 189 self.lickertOptions.hidden = YES;
rt300@0 190 self.interfacePreferenceOptions.hidden = NO;
rt300@0 191 }
rt300@0 192
rt300@0 193 //NSLog(@"Prev answer answerInt %d", curQ.answer);
rt300@0 194 //[picker selectRow:2 inComponent:0 animated:YES];
rt300@0 195
rt300@0 196 // what about unselecting segment?
rt300@0 197
rt300@0 198 }
rt300@0 199 // 1/3/13 removed q 6 and 15. now only 15 qs
rt300@0 200 //----------------------------------------------------------------
rt300@0 201 - (void)populateQuestionArray{
rt300@0 202 // potential leak
rt300@0 203 self.questionArray = [NSArray arrayWithObjects:
rt300@0 204 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
rt300@0 205 [[Question alloc] initWithTextAndType:@"The ability to retrace my steps using the history path was useful...":AGREE_DISAGREE],
rt300@0 206 [[Question alloc] initWithTextAndType:@"The best interface for discovering interesting sounds quickly was...":SLIDERS_ZOOMER],
rt300@0 207 [[Question alloc] initWithTextAndType:@"The best interface for fine tuning a sound was...":SLIDERS_ZOOMER],
rt300@0 208 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
rt300@0 209 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance on the grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
rt300@0 210 [[Question alloc] initWithTextAndType:@"The interface that I felt more in control using was...":SLIDERS_ZOOMER],
rt300@0 211 [[Question alloc] initWithTextAndType:@"Being able to see previously saved presets on the grid is useful.":AGREE_DISAGREE], //
rt300@0 212 [[Question alloc] initWithTextAndType:@"The interface that felt more creative was...":SLIDERS_ZOOMER],
rt300@0 213 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
rt300@0 214 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was...":SLIDERS_ZOOMER],
rt300@0 215 [[Question alloc] initWithTextAndType:@"The interface better for performing live would be...":SLIDERS_ZOOMER],
rt300@0 216 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
rt300@0 217 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
rt300@0 218 [[Question alloc] initWithTextAndType:@"I enjoy 'happy accidents' in the creative process.":AGREE_DISAGREE],
rt300@0 219 [[Question alloc] initWithTextAndType:@"Overall, the interface I preferred using was...":SLIDERS_ZOOMER], // ??????
rt300@0 220 nil];
rt300@0 221 // The zoomer seemed more appropriate to explore the synth sound controls (red) than the note sequence controls (blue)
rt300@0 222 // I enjoyed the sounds produced
rt300@0 223
rt300@0 224 }
rt300@0 225
rt300@0 226 //----------------------------------------------------------------
rt300@0 227 #pragma mark -
rt300@0 228 #pragma mark PickerView DataSource
rt300@0 229
rt300@0 230 - (NSInteger)numberOfComponentsInPickerView:
rt300@0 231 (UIPickerView *)pickerView
rt300@0 232 {
rt300@0 233 return 1;
rt300@0 234 }
rt300@0 235 //----------------------------------------------------------------
rt300@0 236 - (NSInteger)pickerView:(UIPickerView *)pickerView
rt300@0 237 numberOfRowsInComponent:(NSInteger)component
rt300@0 238 {
rt300@0 239
rt300@0 240 return NUM_CHOICES; // always 6
rt300@0 241 }
rt300@0 242 //----------------------------------------------------------------
rt300@0 243 - (NSString *)pickerView:(UIPickerView *)pickerView
rt300@0 244 titleForRow:(NSInteger)row
rt300@0 245 forComponent:(NSInteger)component
rt300@0 246 {
rt300@0 247 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
rt300@0 248
rt300@0 249 // get array of answers from Question class
rt300@0 250 NSArray * answers = [Question answersWithType:curQ.questionType];
rt300@0 251 return [answers objectAtIndex:row];
rt300@0 252
rt300@0 253 }
rt300@0 254 //----------------------------------------------------------------
rt300@0 255 #pragma mark -
rt300@0 256 #pragma mark PickerView Delegate
rt300@0 257 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
rt300@0 258 inComponent:(NSInteger)component
rt300@0 259 {
rt300@0 260 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
rt300@0 261 // set question answerArray
rt300@0 262 curQ.answer = row;
rt300@0 263
rt300@0 264 // chek wot we just rote
rt300@0 265
rt300@0 266 NSLog(@"Answer: %d",curQ.answer);
rt300@0 267
rt300@0 268 }
rt300@0 269 //----------------------------------------------------------------
rt300@0 270 #pragma mark UITextViewDelegate functions
rt300@0 271 /*
rt300@0 272 This answer was useful to me, but I was also looking for the callback function from the "Go" button, which I found is:
rt300@0 273 - (BOOL) textFieldShouldReturn:(UITextField *)textField { // Customer code return YES; }
rt300@0 274
rt300@0 275 You will need to send the UITextField delegate to your view controller for that to work.
rt300@0 276
rt300@0 277 */
rt300@0 278 - (BOOL) textFieldShouldReturn:(UITextField *)textField {
rt300@0 279 // Customer code
rt300@0 280 NSLog(@"RETURN DELEGATE");
rt300@0 281 [self hide:self ];
rt300@0 282 return NO;
rt300@0 283 }
rt300@0 284 - (IBAction)answerChosen:(id)sender {
rt300@0 285 self.pleaseAnswer.hidden = YES;
rt300@0 286 UISegmentedControl *seg = (UISegmentedControl *)sender;
rt300@0 287 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
rt300@0 288 // set question answerArray
rt300@0 289 curQ.answer = seg.selectedSegmentIndex;
rt300@0 290
rt300@0 291 // chek wot we just rote
rt300@0 292
rt300@0 293 NSLog(@"Answer: %d",curQ.answer);
rt300@0 294
rt300@0 295 // automatically go next q
rt300@0 296 self.currentQuestionIndex++;
rt300@0 297 if(self.currentQuestionIndex >= [self.questionArray count]){
rt300@0 298 [self showThanks];
rt300@0 299 }else{
rt300@0 300 [self loadQuestion:self.currentQuestionIndex];
rt300@0 301
rt300@0 302 }
rt300@0 303
rt300@0 304 }
rt300@0 305 @end // end implementation
rt300@0 306 //----------------------------------------------------------------
rt300@0 307 //----------------------------------------------------------------