annotate QuestionnaireViewController.mm @ 16:fb2ef16dd013

Split alert views. Settled on using portrait mode.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 17 Jan 2013 18:21:48 +0000
parents
children 650589cac373
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@16 12 @interface QuestionnaireViewController ()
rt300@16 13 // the "model" is an array of questions and a bunch of answers
rt300@16 14 @property (strong, nonatomic) NSArray * questionArray;
rt300@16 15 @property (strong, nonatomic) NSMutableArray * answerArray;
rt300@16 16 @property (nonatomic) NSInteger currentQuestionIndex;
rt300@16 17 @property (nonatomic) id theOFAppRef;
rt300@16 18 /*
rt300@16 19
rt300@16 20
rt300@16 21 */
rt300@16 22
rt300@16 23 @end
rt300@16 24
rt300@16 25 @implementation QuestionnaireViewController
rt300@16 26
rt300@16 27 @synthesize nextButton = _nextButton;
rt300@16 28 @synthesize segControl = _segControl;
rt300@16 29
rt300@16 30 //----------------------------------------------------------------
rt300@16 31 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
rt300@16 32 {
rt300@16 33 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
rt300@16 34 if (self) {
rt300@16 35 // Custom initialization
rt300@16 36
rt300@16 37 [self populateQuestionArray ];
rt300@16 38 [self populateAnswerArray];
rt300@16 39
rt300@16 40 }
rt300@16 41 return self;
rt300@16 42 }
rt300@16 43 - (void)setAppRef:(id)theOFApp{
rt300@16 44 self.theOFAppRef = theOFApp;
rt300@16 45
rt300@16 46 }
rt300@16 47 //----------------------------------------------------------------
rt300@16 48 - (void)viewDidLoad
rt300@16 49 {
rt300@16 50 [super viewDidLoad];
rt300@16 51 // Do any additional setup after loading the view from its nib.
rt300@16 52 self.currentQuestionIndex = 0;
rt300@16 53 // load question 1
rt300@16 54 [self loadQuestion:self.currentQuestionIndex];
rt300@16 55 }
rt300@16 56 //----------------------------------------------------------------
rt300@16 57 - (void)didReceiveMemoryWarning
rt300@16 58 {
rt300@16 59 [super didReceiveMemoryWarning];
rt300@16 60 // Dispose of any resources that can be recreated.
rt300@16 61 }
rt300@16 62 //----------------------------------------------------------------
rt300@16 63 - (void)dealloc {
rt300@16 64
rt300@16 65 [_questionText release];
rt300@16 66 [_titleText release];
rt300@16 67 [_finishButton release];
rt300@16 68 [_nextButton release];
rt300@16 69 [_segControl release];
rt300@16 70 [super dealloc];
rt300@16 71 }
rt300@16 72 //----------------------------------------------------------------
rt300@16 73 - (void)viewDidUnload {
rt300@16 74 [self setQuestionText:nil];
rt300@16 75 [self setTitleText:nil];
rt300@16 76 [self setFinishButton:nil];
rt300@16 77 [self setNextButton:nil];
rt300@16 78 [self setSegControl:nil];
rt300@16 79 [super viewDidUnload];
rt300@16 80 }
rt300@16 81 //----------------------------------------------------------------
rt300@16 82 - (IBAction)answerWasSelected:(id)sender {
rt300@16 83 // look at property?
rt300@16 84
rt300@16 85 }
rt300@16 86
rt300@16 87 //----------------------------------------------------------------
rt300@16 88 -(IBAction)hide:(id)sender{
rt300@16 89 // c++ call with NSArray argument??
rt300@16 90 ((testApp *)self.theOFAppRef)->questionnaireHidden(self.answerArray);
rt300@16 91 self.view.hidden = YES;
rt300@16 92 }
rt300@16 93 //----------------------------------------------------------------
rt300@16 94 -(IBAction)show:(id)sender{
rt300@16 95 self.view.hidden = NO;
rt300@16 96 }
rt300@16 97 //----------------------------------------------------------------
rt300@16 98
rt300@16 99 - (IBAction)nextQuestionPressed:(id)sender {
rt300@16 100 // save answer ? no button did that hopefully
rt300@16 101
rt300@16 102 // if last question show thanks
rt300@16 103 // else go to next
rt300@16 104 self.currentQuestionIndex++;
rt300@16 105 if(self.currentQuestionIndex >= [self.questionArray count]){
rt300@16 106 [self showThanks];
rt300@16 107 }else{
rt300@16 108 [self loadQuestion:self.currentQuestionIndex];
rt300@16 109
rt300@16 110 }
rt300@16 111 }
rt300@16 112 //----------------------------------------------------------------
rt300@16 113 - (IBAction)previousQuestionPressed:(id)sender {
rt300@16 114 self.currentQuestionIndex--;
rt300@16 115 if(self.currentQuestionIndex < 0){
rt300@16 116 // nothing
rt300@16 117 self.currentQuestionIndex = 0;
rt300@16 118 }else{
rt300@16 119 [self loadQuestion:self.currentQuestionIndex];
rt300@16 120 }
rt300@16 121 }
rt300@16 122
rt300@16 123 - (IBAction)answerSelected:(id)sender {
rt300@16 124 // nice short lines of code.
rt300@16 125
rt300@16 126 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
rt300@16 127
rt300@16 128 // chek wot we just rote
rt300@16 129 // DUZZNT WERK
rt300@16 130 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
rt300@16 131
rt300@16 132
rt300@16 133 }
rt300@16 134 //----------------------------------------------------------------
rt300@16 135
rt300@16 136 - (void)showThanks{
rt300@16 137 // hide next question button
rt300@16 138 self.nextButton.hidden = YES;
rt300@16 139 // hide selector
rt300@16 140 self.segControl.hidden = YES;
rt300@16 141
rt300@16 142
rt300@16 143 self.titleText.text = @"Thank you!";
rt300@16 144
rt300@16 145 self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events.";
rt300@16 146 }
rt300@16 147
rt300@16 148 //----------------------------------------------------------------
rt300@16 149 - (void)loadQuestion:(NSInteger)questionIndex {
rt300@16 150 // populate text fields with question
rt300@16 151 NSString *qtitle;
rt300@16 152 qtitle = [@"Question " stringByAppendingFormat:@"%d",questionIndex+1];
rt300@16 153 self.titleText.text = qtitle;
rt300@16 154
rt300@16 155 self.questionText.text = [self.questionArray objectAtIndex:questionIndex];
rt300@16 156
rt300@16 157 // if question already answered show that
rt300@16 158 self.segControl.selectedSegmentIndex = (NSInteger)[self.answerArray objectAtIndex:self.currentQuestionIndex];
rt300@16 159 }
rt300@16 160 //----------------------------------------------------------------
rt300@16 161 - (void)populateQuestionArray{
rt300@16 162 self.questionArray = [[NSArray alloc] initWithObjects:
rt300@16 163 @"I am familiar with music software and synthesisers.",
rt300@16 164 @"The best way to get a feel for the possibilities of the synth was with:",
rt300@16 165 @"Interesting sounds could be discovered more quickly as a result of using:",
rt300@16 166 @"A sound could be fine tuned more easily using:",
rt300@16 167 @"The correspondence between the sliders and the grid was understandable.",
rt300@16 168 @"The interface that felt more familiar was:",
rt300@16 169 @"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.",
rt300@16 170 @"The ability to see other presets on the grid was useful.",
rt300@16 171 @"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.",
rt300@16 172 @"The interface better for generating new ideas was",
rt300@16 173 @"The interface better for live performance would be:",
rt300@16 174 @"A specific type of sound could be found more quickly using:",
rt300@16 175 @"I felt more in control when using:",
rt300@16 176 @"The Zoomer was an improvement on just using a randomiser.",
rt300@16 177 @"The combination of Zoomer and Sliders was more useful than either individually.",
rt300@16 178 @"Overall, I preferred using:",
rt300@16 179 nil];
rt300@16 180 }
rt300@16 181 //----------------------------------------------------------------
rt300@16 182 - (void)populateAnswerArray{
rt300@16 183 int N = [self.questionArray count];
rt300@16 184
rt300@16 185 //[self.answerArray initWithCapacity:N]; // necessary?
rt300@16 186 self.answerArray = [[NSMutableArray alloc] initWithCapacity:N];
rt300@16 187 // set the number to what?
rt300@16 188 for(int i=0;i<N;i++){
rt300@16 189 [self.answerArray addObject:[NSNumber numberWithInt:-1]];
rt300@16 190 }
rt300@16 191 NSLog(@"Answer count: %d", [self.answerArray count]);
rt300@16 192
rt300@16 193 }
rt300@16 194
rt300@16 195 @end // end implementation