diff QuestionnaireViewController.mm @ 21:650589cac373

Picker view stuff started.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 18 Jan 2013 15:48:33 +0000
parents fb2ef16dd013
children 8c0783739337
line wrap: on
line diff
--- a/QuestionnaireViewController.mm	Thu Jan 17 21:41:55 2013 +0000
+++ b/QuestionnaireViewController.mm	Fri Jan 18 15:48:33 2013 +0000
@@ -9,12 +9,18 @@
 #import "QuestionnaireViewController.h"
 
 #include "testApp.h"
+
+#pragma mark -
+#pragma mark QuestionnaireViewController
+
 @interface QuestionnaireViewController ()
     // the "model" is an array of questions and a bunch of answers
-@property (strong, nonatomic) NSArray * questionArray;
-@property (strong, nonatomic) NSMutableArray * answerArray;
-@property (nonatomic) NSInteger currentQuestionIndex;
-@property (nonatomic) id theOFAppRef;
+@property (strong, nonatomic)       NSArray * questionArray;
+@property (strong, nonatomic)       NSArray * answerTypeArray;
+@property (strong, nonatomic)       NSMutableArray * answerArray;
+@property (nonatomic)               NSInteger currentQuestionIndex;
+@property (nonatomic, assign)       id theOFAppRef;
+
 /*
 
 
@@ -24,6 +30,10 @@
 
 @implementation QuestionnaireViewController
 
+@synthesize picker;
+@synthesize agreeAnswer;
+@synthesize agreeType;
+@synthesize answerTypeArray;
 @synthesize nextButton = _nextButton;
 @synthesize segControl = _segControl;
 
@@ -51,6 +61,16 @@
     // Do any additional setup after loading the view from its nib.
     self.currentQuestionIndex = 0;
     // load question 1
+    
+    self.agreeAnswer = [[NSArray alloc] initWithObjects:
+                        @"Strongly disagree", @"Disagree", @"Neither",
+                        @"Agree", @"Strongly agree", nil];
+    
+    self.interfaceAnswer = [[NSArray alloc] initWithObjects:
+                            @"Definitely Sliders", @"Maybe Sliders", @"Neither",
+                            @"Maybe Zoomer", @"Definitely Zoomer", nil];
+    agreeType = YES;
+    
     [self loadQuestion:self.currentQuestionIndex];
 }
 //----------------------------------------------------------------
@@ -119,14 +139,16 @@
         [self loadQuestion:self.currentQuestionIndex];
     }
 }
+//----------------------------------------------------------------
 
+// NAH
 - (IBAction)answerSelected:(id)sender {
     // nice short lines of code.
     
     [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
     
     // chek wot we just rote
-    // DUZZNT WERK
+    
     NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
     
     
@@ -149,13 +171,31 @@
 - (void)loadQuestion:(NSInteger)questionIndex {
     // populate text fields with question
     NSString *qtitle;
-    qtitle = [@"Question " stringByAppendingFormat:@"%d",questionIndex+1];
+    qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
     self.titleText.text = qtitle;
     
     self.questionText.text = [self.questionArray objectAtIndex:questionIndex];
     
     // if question already answered show that
-    self.segControl.selectedSegmentIndex = (NSInteger)[self.answerArray objectAtIndex:self.currentQuestionIndex];
+    NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue];
+    
+    // set different answer type
+    agreeType = [answerTypeArray objectAtIndex:questionIndex];
+    // then refresh picker view content
+    [picker reloadComponent:0];
+    
+
+    // DUZZNT WERK
+    if(answerInt==-1){
+        // select "neither" (2)
+        NSLog(@"No answer answerInt %d", answerInt);
+        [picker selectRow:2 inComponent:0 animated:YES];
+        
+    }else{
+        // select previous answer
+        NSLog(@"Prev answer answerInt %d", answerInt);
+        [picker selectRow:answerInt inComponent:0 animated:YES];
+    }
 }
 //----------------------------------------------------------------
 - (void)populateQuestionArray{
@@ -177,6 +217,24 @@
                           @"The combination of Zoomer and Sliders was more useful than either individually.",
                           @"Overall, I preferred using:",
                           nil];
+    self.answerTypeArray = [[NSArray alloc] initWithObjects:
+                            YES,
+                            NO,
+                            NO,
+                            NO,
+                            YES,
+                            NO,
+                            YES,
+                            YES,
+                            YES,
+                            NO,
+                            NO,
+                            NO,
+                            NO,
+                            YES,
+                            YES,
+                            NO,
+                            nil]
 }
 //----------------------------------------------------------------
 - (void)populateAnswerArray{
@@ -188,8 +246,57 @@
     for(int i=0;i<N;i++){
         [self.answerArray addObject:[NSNumber numberWithInt:-1]];
     }
-    NSLog(@"Answer count: %d", [self.answerArray count]);
     
 }
+//----------------------------------------------------------------
+#pragma mark -
+#pragma mark PickerView DataSource
 
-@end // end implementation
\ No newline at end of file
+- (NSInteger)numberOfComponentsInPickerView:
+(UIPickerView *)pickerView
+{
+    return 1;
+}
+- (NSInteger)pickerView:(UIPickerView *)pickerView
+numberOfRowsInComponent:(NSInteger)component
+{
+    return [agreeAnswer count]; // always 5
+}
+- (NSString *)pickerView:(UIPickerView *)pickerView
+             titleForRow:(NSInteger)row
+            forComponent:(NSInteger)component
+{
+    if(agreeType){
+        return [agreeAnswer objectAtIndex:row];
+    }else{
+        return [interfaceAnswer objectAtIndex:row];
+    }
+}
+
+#pragma mark -
+#pragma mark PickerView Delegate
+-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
+      inComponent:(NSInteger)component
+{
+    
+    // set question answerArray
+    [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:row]];
+    
+    // chek wot we just rote
+    
+    NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
+    /*
+     float rate = [[exchangeRates objectAtIndex:row] floatValue];
+     float dollars = [dollarText.text floatValue];
+     float result = dollars * rate;
+     
+     NSString *resultString = [[NSString alloc] initWithFormat:
+     @"%.2f USD = %.2f %@", dollars, result,
+     [countryNames objectAtIndex:row]];
+     resultLabel.text = resultString;
+     */
+}
+
+@end // end implementation
+//----------------------------------------------------------------
+//----------------------------------------------------------------