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