rt300@16: // rt300@16: // QuestionnaireViewController.m rt300@16: // oscSenderExample rt300@16: // rt300@16: // Created by Robert Tubb on 16/01/2013. rt300@16: // rt300@16: // rt300@16: rt300@16: #import "QuestionnaireViewController.h" rt300@16: rt300@16: #include "testApp.h" rt300@21: rt300@21: #pragma mark - rt300@21: #pragma mark QuestionnaireViewController rt300@21: rt300@16: @interface QuestionnaireViewController () rt300@16: // the "model" is an array of questions and a bunch of answers rt300@21: @property (strong, nonatomic) NSArray * questionArray; rt300@21: @property (strong, nonatomic) NSArray * answerTypeArray; rt300@21: @property (strong, nonatomic) NSMutableArray * answerArray; rt300@21: @property (nonatomic) NSInteger currentQuestionIndex; rt300@21: @property (nonatomic, assign) id theOFAppRef; rt300@21: rt300@16: /* rt300@16: rt300@16: rt300@16: */ rt300@16: rt300@16: @end rt300@16: rt300@16: @implementation QuestionnaireViewController rt300@16: rt300@21: @synthesize picker; rt300@21: @synthesize agreeAnswer; rt300@21: @synthesize agreeType; rt300@21: @synthesize answerTypeArray; rt300@16: @synthesize nextButton = _nextButton; rt300@16: @synthesize segControl = _segControl; rt300@16: rt300@16: //---------------------------------------------------------------- rt300@16: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil rt300@16: { rt300@16: self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; rt300@16: if (self) { rt300@16: // Custom initialization rt300@16: rt300@16: [self populateQuestionArray ]; rt300@16: [self populateAnswerArray]; rt300@16: rt300@16: } rt300@16: return self; rt300@16: } rt300@16: - (void)setAppRef:(id)theOFApp{ rt300@16: self.theOFAppRef = theOFApp; rt300@16: rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)viewDidLoad rt300@16: { rt300@16: [super viewDidLoad]; rt300@16: // Do any additional setup after loading the view from its nib. rt300@16: self.currentQuestionIndex = 0; rt300@16: // load question 1 rt300@21: rt300@21: self.agreeAnswer = [[NSArray alloc] initWithObjects: rt300@21: @"Strongly disagree", @"Disagree", @"Neither", rt300@21: @"Agree", @"Strongly agree", nil]; rt300@21: rt300@21: self.interfaceAnswer = [[NSArray alloc] initWithObjects: rt300@21: @"Definitely Sliders", @"Maybe Sliders", @"Neither", rt300@21: @"Maybe Zoomer", @"Definitely Zoomer", nil]; rt300@21: agreeType = YES; rt300@21: rt300@16: [self loadQuestion:self.currentQuestionIndex]; rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)didReceiveMemoryWarning rt300@16: { rt300@16: [super didReceiveMemoryWarning]; rt300@16: // Dispose of any resources that can be recreated. rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)dealloc { rt300@16: rt300@16: [_questionText release]; rt300@16: [_titleText release]; rt300@16: [_finishButton release]; rt300@16: [_nextButton release]; rt300@16: [_segControl release]; rt300@16: [super dealloc]; rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)viewDidUnload { rt300@16: [self setQuestionText:nil]; rt300@16: [self setTitleText:nil]; rt300@16: [self setFinishButton:nil]; rt300@16: [self setNextButton:nil]; rt300@16: [self setSegControl:nil]; rt300@16: [super viewDidUnload]; rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (IBAction)answerWasSelected:(id)sender { rt300@16: // look at property? rt300@16: rt300@16: } rt300@16: rt300@16: //---------------------------------------------------------------- rt300@16: -(IBAction)hide:(id)sender{ rt300@16: // c++ call with NSArray argument?? rt300@16: ((testApp *)self.theOFAppRef)->questionnaireHidden(self.answerArray); rt300@16: self.view.hidden = YES; rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: -(IBAction)show:(id)sender{ rt300@16: self.view.hidden = NO; rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: rt300@16: - (IBAction)nextQuestionPressed:(id)sender { rt300@16: // save answer ? no button did that hopefully rt300@16: rt300@16: // if last question show thanks rt300@16: // else go to next rt300@16: self.currentQuestionIndex++; rt300@16: if(self.currentQuestionIndex >= [self.questionArray count]){ rt300@16: [self showThanks]; rt300@16: }else{ rt300@16: [self loadQuestion:self.currentQuestionIndex]; rt300@16: rt300@16: } rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (IBAction)previousQuestionPressed:(id)sender { rt300@16: self.currentQuestionIndex--; rt300@16: if(self.currentQuestionIndex < 0){ rt300@16: // nothing rt300@16: self.currentQuestionIndex = 0; rt300@16: }else{ rt300@16: [self loadQuestion:self.currentQuestionIndex]; rt300@16: } rt300@16: } rt300@21: //---------------------------------------------------------------- rt300@16: rt300@21: // NAH rt300@16: - (IBAction)answerSelected:(id)sender { rt300@16: // nice short lines of code. rt300@16: rt300@16: [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]]; rt300@16: rt300@16: // chek wot we just rote rt300@21: rt300@16: NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]); rt300@16: rt300@16: rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: rt300@16: - (void)showThanks{ rt300@16: // hide next question button rt300@16: self.nextButton.hidden = YES; rt300@16: // hide selector rt300@16: self.segControl.hidden = YES; rt300@16: rt300@16: rt300@16: self.titleText.text = @"Thank you!"; rt300@16: rt300@16: self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events."; rt300@16: } rt300@16: rt300@16: //---------------------------------------------------------------- rt300@16: - (void)loadQuestion:(NSInteger)questionIndex { rt300@16: // populate text fields with question rt300@16: NSString *qtitle; rt300@21: qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1]; rt300@16: self.titleText.text = qtitle; rt300@16: rt300@16: self.questionText.text = [self.questionArray objectAtIndex:questionIndex]; rt300@16: rt300@16: // if question already answered show that rt300@21: NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue]; rt300@21: rt300@21: // set different answer type rt300@21: agreeType = [answerTypeArray objectAtIndex:questionIndex]; rt300@21: // then refresh picker view content rt300@21: [picker reloadComponent:0]; rt300@21: rt300@21: rt300@21: // DUZZNT WERK rt300@21: if(answerInt==-1){ rt300@21: // select "neither" (2) rt300@21: NSLog(@"No answer answerInt %d", answerInt); rt300@21: [picker selectRow:2 inComponent:0 animated:YES]; rt300@21: rt300@21: }else{ rt300@21: // select previous answer rt300@21: NSLog(@"Prev answer answerInt %d", answerInt); rt300@21: [picker selectRow:answerInt inComponent:0 animated:YES]; rt300@21: } rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)populateQuestionArray{ rt300@16: self.questionArray = [[NSArray alloc] initWithObjects: rt300@16: @"I am familiar with music software and synthesisers.", rt300@16: @"The best way to get a feel for the possibilities of the synth was with:", rt300@16: @"Interesting sounds could be discovered more quickly as a result of using:", rt300@16: @"A sound could be fine tuned more easily using:", rt300@16: @"The correspondence between the sliders and the grid was understandable.", rt300@16: @"The interface that felt more familiar was:", rt300@16: @"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.", rt300@16: @"The ability to see other presets on the grid was useful.", rt300@16: @"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.", rt300@16: @"The interface better for generating new ideas was", rt300@16: @"The interface better for live performance would be:", rt300@16: @"A specific type of sound could be found more quickly using:", rt300@16: @"I felt more in control when using:", rt300@16: @"The Zoomer was an improvement on just using a randomiser.", rt300@16: @"The combination of Zoomer and Sliders was more useful than either individually.", rt300@16: @"Overall, I preferred using:", rt300@16: nil]; rt300@21: self.answerTypeArray = [[NSArray alloc] initWithObjects: rt300@21: YES, rt300@21: NO, rt300@21: NO, rt300@21: NO, rt300@21: YES, rt300@21: NO, rt300@21: YES, rt300@21: YES, rt300@21: YES, rt300@21: NO, rt300@21: NO, rt300@21: NO, rt300@21: NO, rt300@21: YES, rt300@21: YES, rt300@21: NO, rt300@21: nil] rt300@16: } rt300@16: //---------------------------------------------------------------- rt300@16: - (void)populateAnswerArray{ rt300@16: int N = [self.questionArray count]; rt300@16: rt300@16: //[self.answerArray initWithCapacity:N]; // necessary? rt300@16: self.answerArray = [[NSMutableArray alloc] initWithCapacity:N]; rt300@16: // set the number to what? rt300@16: for(int i=0;i