iosresearchkit

ResearchKit: Change choices based on previous response


Im working on Survey app using ResearchKit and I need to change the values of the next question based on the previous response. Example:

Question 1: How many cars do you have?
- 1 Car
- 2 Cars
- 3 Cars
- 4 Cars
- xx Cars

Question 2: Which is your favorite car?
 - car number 1
 - car number 2
 - car number 3
 - car number 4
 - car number XX

The number of options of the question 2 will based on the value selected on Question 1.

Any idea how can I do that?


Solution

  • I found out a solution, while it is not possible to create new steps after you presented the ViewController, It is possible to update answerFormat of a step using a new array

    for(ORKQuestionStep* step in ((ORKOrderedTask*)self.task).steps) {
                if([step.answerFormat isKindOfClass:[ORKValuePickerAnswerFormat class]]) {
                   step.answerFormat = [[ORKValuePickerAnswerFormat alloc] initWithTextChoices:arrayOfChoices];
                }
            }