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@22
|
17 // the "model" is an array of questions
|
rt300@21
|
18 @property (strong, nonatomic) NSArray * questionArray;
|
rt300@21
|
19 @property (nonatomic) NSInteger currentQuestionIndex;
|
rt300@21
|
20 @property (nonatomic, assign) id theOFAppRef;
|
rt300@21
|
21
|
rt300@16
|
22 /*
|
rt300@16
|
23
|
rt300@16
|
24
|
rt300@16
|
25 */
|
rt300@16
|
26
|
rt300@16
|
27 @end
|
rt300@16
|
28
|
rt300@16
|
29 @implementation QuestionnaireViewController
|
rt300@16
|
30
|
rt300@21
|
31 @synthesize picker;
|
rt300@16
|
32 @synthesize nextButton = _nextButton;
|
rt300@22
|
33 @synthesize questionArray;
|
rt300@22
|
34
|
rt300@16
|
35
|
rt300@16
|
36 //----------------------------------------------------------------
|
rt300@16
|
37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
rt300@16
|
38 {
|
rt300@16
|
39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
rt300@16
|
40 if (self) {
|
rt300@16
|
41 // Custom initialization
|
rt300@16
|
42
|
rt300@16
|
43 [self populateQuestionArray ];
|
rt300@16
|
44
|
rt300@16
|
45 }
|
rt300@16
|
46 return self;
|
rt300@16
|
47 }
|
rt300@16
|
48 - (void)setAppRef:(id)theOFApp{
|
rt300@16
|
49 self.theOFAppRef = theOFApp;
|
rt300@16
|
50
|
rt300@16
|
51 }
|
rt300@16
|
52 //----------------------------------------------------------------
|
rt300@16
|
53 - (void)viewDidLoad
|
rt300@16
|
54 {
|
rt300@16
|
55 [super viewDidLoad];
|
rt300@16
|
56 // Do any additional setup after loading the view from its nib.
|
rt300@16
|
57 self.currentQuestionIndex = 0;
|
rt300@21
|
58
|
rt300@22
|
59 // load question 1
|
rt300@22
|
60 [self loadQuestion:self.currentQuestionIndex];
|
rt300@21
|
61
|
rt300@22
|
62 self.previousButton.hidden = YES; // dont bother
|
rt300@21
|
63
|
rt300@16
|
64 }
|
rt300@16
|
65 //----------------------------------------------------------------
|
rt300@16
|
66 - (void)didReceiveMemoryWarning
|
rt300@16
|
67 {
|
rt300@16
|
68 [super didReceiveMemoryWarning];
|
rt300@16
|
69 // Dispose of any resources that can be recreated.
|
rt300@16
|
70 }
|
rt300@16
|
71 //----------------------------------------------------------------
|
rt300@16
|
72 - (void)dealloc {
|
rt300@16
|
73
|
rt300@16
|
74 [_questionText release];
|
rt300@16
|
75 [_titleText release];
|
rt300@16
|
76 [_finishButton release];
|
rt300@16
|
77 [_nextButton release];
|
rt300@22
|
78 [_previousButton release];
|
rt300@16
|
79 [super dealloc];
|
rt300@16
|
80 }
|
rt300@16
|
81 //----------------------------------------------------------------
|
rt300@16
|
82 - (void)viewDidUnload {
|
rt300@16
|
83 [self setQuestionText:nil];
|
rt300@16
|
84 [self setTitleText:nil];
|
rt300@16
|
85 [self setFinishButton:nil];
|
rt300@16
|
86 [self setNextButton:nil];
|
rt300@22
|
87 [self setPreviousButton:nil];
|
rt300@16
|
88 [super viewDidUnload];
|
rt300@16
|
89 }
|
rt300@16
|
90 //----------------------------------------------------------------
|
rt300@22
|
91 -(IBAction)hide:(id)sender{
|
rt300@22
|
92 // called when finish button hit
|
rt300@22
|
93 // c++ call with NSArray argument??
|
rt300@22
|
94 // load answers into a c++ vector;
|
rt300@22
|
95 vector<int> answersArray;
|
rt300@22
|
96
|
rt300@22
|
97 Question *q;
|
rt300@16
|
98
|
rt300@22
|
99 for(int i=0;i<[questionArray count];i++){
|
rt300@22
|
100 q = [questionArray objectAtIndex:i];
|
rt300@22
|
101 answersArray.push_back(q.answer);
|
rt300@22
|
102
|
rt300@22
|
103 }
|
rt300@22
|
104
|
rt300@22
|
105 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray);
|
rt300@16
|
106 self.view.hidden = YES;
|
rt300@16
|
107 }
|
rt300@16
|
108 //----------------------------------------------------------------
|
rt300@16
|
109 -(IBAction)show:(id)sender{
|
rt300@16
|
110 self.view.hidden = NO;
|
rt300@16
|
111 }
|
rt300@16
|
112 //----------------------------------------------------------------
|
rt300@16
|
113
|
rt300@16
|
114 - (IBAction)nextQuestionPressed:(id)sender {
|
rt300@16
|
115 // save answer ? no button did that hopefully
|
rt300@16
|
116
|
rt300@16
|
117 // if last question show thanks
|
rt300@16
|
118 // else go to next
|
rt300@16
|
119 self.currentQuestionIndex++;
|
rt300@16
|
120 if(self.currentQuestionIndex >= [self.questionArray count]){
|
rt300@16
|
121 [self showThanks];
|
rt300@16
|
122 }else{
|
rt300@16
|
123 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
124
|
rt300@16
|
125 }
|
rt300@16
|
126 }
|
rt300@16
|
127 //----------------------------------------------------------------
|
rt300@16
|
128 - (IBAction)previousQuestionPressed:(id)sender {
|
rt300@16
|
129 self.currentQuestionIndex--;
|
rt300@16
|
130 if(self.currentQuestionIndex < 0){
|
rt300@16
|
131 // nothing
|
rt300@16
|
132 self.currentQuestionIndex = 0;
|
rt300@16
|
133 }else{
|
rt300@16
|
134 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
135 }
|
rt300@16
|
136 }
|
rt300@16
|
137
|
rt300@16
|
138 //----------------------------------------------------------------
|
rt300@16
|
139
|
rt300@16
|
140 - (void)showThanks{
|
rt300@16
|
141 // hide next question button
|
rt300@16
|
142 self.nextButton.hidden = YES;
|
rt300@16
|
143 // hide selector
|
rt300@22
|
144 self.picker.hidden = YES;
|
rt300@22
|
145 self.previousButton.hidden = YES;
|
rt300@16
|
146
|
rt300@16
|
147 self.titleText.text = @"Thank you!";
|
rt300@16
|
148
|
rt300@16
|
149 self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events.";
|
rt300@16
|
150 }
|
rt300@16
|
151
|
rt300@16
|
152 //----------------------------------------------------------------
|
rt300@16
|
153 - (void)loadQuestion:(NSInteger)questionIndex {
|
rt300@16
|
154 // populate text fields with question
|
rt300@16
|
155 NSString *qtitle;
|
rt300@21
|
156 qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
|
rt300@16
|
157 self.titleText.text = qtitle;
|
rt300@16
|
158
|
rt300@22
|
159 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@16
|
160
|
rt300@22
|
161 self.questionText.text = curQ.questionText;
|
rt300@21
|
162
|
rt300@22
|
163
|
rt300@22
|
164 // refresh picker view content
|
rt300@21
|
165 [picker reloadComponent:0];
|
rt300@21
|
166
|
rt300@21
|
167
|
rt300@22
|
168 NSLog(@"Prev answer answerInt %d", curQ.answer);
|
rt300@22
|
169 [picker selectRow:curQ.answer inComponent:0 animated:YES];
|
rt300@22
|
170
|
rt300@16
|
171 }
|
rt300@16
|
172 //----------------------------------------------------------------
|
rt300@16
|
173 - (void)populateQuestionArray{
|
rt300@22
|
174
|
rt300@22
|
175 self.questionArray = [NSArray arrayWithObjects:
|
rt300@22
|
176 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
|
rt300@22
|
177 [[Question alloc] initWithTextAndType:@"The best way to get a feel for the possibilities of the synth was with:":SLIDERS_ZOOMER],
|
rt300@22
|
178 [[Question alloc] initWithTextAndType:@"Interesting sounds could be discovered more quickly as a result of using:":SLIDERS_ZOOMER],
|
rt300@22
|
179 [[Question alloc] initWithTextAndType:@"A sound could be fine tuned more easily using:":SLIDERS_ZOOMER],
|
rt300@22
|
180 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
|
rt300@22
|
181 [[Question alloc] initWithTextAndType:@"The interface that felt more familiar was:":SLIDERS_ZOOMER],
|
rt300@22
|
182 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
|
rt300@22
|
183 [[Question alloc] initWithTextAndType:@"The ability to see other presets on the grid was useful.":AGREE_DISAGREE],
|
rt300@22
|
184 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
|
rt300@22
|
185 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was":SLIDERS_ZOOMER],
|
rt300@22
|
186 [[Question alloc] initWithTextAndType:@"The interface better for live performance would be:":SLIDERS_ZOOMER],
|
rt300@22
|
187 [[Question alloc] initWithTextAndType:@"A specific type of sound could be found more quickly using:":SLIDERS_ZOOMER],
|
rt300@22
|
188 [[Question alloc] initWithTextAndType:@"I felt more in control when using:":SLIDERS_ZOOMER],
|
rt300@22
|
189 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
|
rt300@22
|
190 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
|
rt300@22
|
191 [[Question alloc] initWithTextAndType:@"Overall, I preferred using:":SLIDERS_ZOOMER],
|
rt300@16
|
192 nil];
|
rt300@22
|
193
|
rt300@16
|
194 }
|
rt300@16
|
195
|
rt300@21
|
196 //----------------------------------------------------------------
|
rt300@21
|
197 #pragma mark -
|
rt300@21
|
198 #pragma mark PickerView DataSource
|
rt300@16
|
199
|
rt300@21
|
200 - (NSInteger)numberOfComponentsInPickerView:
|
rt300@21
|
201 (UIPickerView *)pickerView
|
rt300@21
|
202 {
|
rt300@21
|
203 return 1;
|
rt300@21
|
204 }
|
rt300@22
|
205 //----------------------------------------------------------------
|
rt300@21
|
206 - (NSInteger)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
207 numberOfRowsInComponent:(NSInteger)component
|
rt300@21
|
208 {
|
rt300@22
|
209 return 6; // always 6
|
rt300@21
|
210 }
|
rt300@22
|
211 //----------------------------------------------------------------
|
rt300@21
|
212 - (NSString *)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
213 titleForRow:(NSInteger)row
|
rt300@21
|
214 forComponent:(NSInteger)component
|
rt300@21
|
215 {
|
rt300@22
|
216 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@22
|
217
|
rt300@22
|
218 // get array of answers from Question class
|
rt300@22
|
219 NSArray * answers = [Question answersWithType:curQ.questionType];
|
rt300@22
|
220 return [answers objectAtIndex:row];
|
rt300@22
|
221
|
rt300@21
|
222 }
|
rt300@22
|
223 //----------------------------------------------------------------
|
rt300@21
|
224 #pragma mark -
|
rt300@21
|
225 #pragma mark PickerView Delegate
|
rt300@21
|
226 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
|
rt300@21
|
227 inComponent:(NSInteger)component
|
rt300@21
|
228 {
|
rt300@22
|
229 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@21
|
230 // set question answerArray
|
rt300@22
|
231 curQ.answer = row;
|
rt300@21
|
232
|
rt300@21
|
233 // chek wot we just rote
|
rt300@21
|
234
|
rt300@22
|
235 NSLog(@"Answer: %d",curQ.answer);
|
rt300@22
|
236
|
rt300@21
|
237 }
|
rt300@21
|
238
|
rt300@21
|
239 @end // end implementation
|
rt300@21
|
240 //----------------------------------------------------------------
|
rt300@21
|
241 //----------------------------------------------------------------
|